Hi,

I'm binding data table to datagrid but i'm not sure how to delete the empty cells in that data table
Plz find the below image

could anyone suggest the best way to delete the empty cells as marked in black pen

Thanks

Recommended Answers

All 8 Replies

Perhaps someone will come along with an ingenious way to delete the cells that I'm not aware of, but offhand I'd say the problem and therefore the solution lies in your datatable and by extension datastorage or query.

You seem to be thinking of the datagrid in the context of a spread sheet which it really isn't. How are you populating the datatable? It might be as simple as modifying the query, even if it's awful database design.

I have data getting from query where in i need to modify 4-5 columns and make a single column,thn create new row and add it to data table
So everytime i'm adding new row its creating new rows and that the problem
I can't do much b'cos i get data completely dynamically,so i did not find anyway to add to the existing rows with creating new column

Thanks

I have data getting from query where in i need to modify 4-5 columns and make a single column,thn create new row and add it to data table
So everytime i'm adding new row its creating new rows and that the problem
I can't do much b'cos i get data completely dynamically,so i did not find anyway to add to the existing rows with creating new column

Thanks

Basically you are looking at merging rows of data, which you might accomplish using a second datatable, although I suspect there is a solution to be found in the process of creating and populating your current datatable.

The process goes like this...
I have a checked listbox where in user selects some employees and want to see his details
so i'm looping through chkedlistbox and passing input paramter as empID to query and getting his details and creating new row and adding his details in data table as shown above
So everytime i can get only one employee details as recordset to my query.
Once i get each employee details i add them to datatable as newrow
looping through recordset.
Plz let me know if you need any more information
Thanks

It sounds like you could check the count of the records returned by the query against the count of records in your datatable and then loop through the datatable modifying the row instead of adding new one until your query record count exceeded your datatable row count and then start adding new records.

Yes that is one of the idea but i feel there should be some simple way to delete the empty cells in the data table

Yes that is one of the idea but i feel there should be some simple way to delete the empty cells in the data table

I understand where you've come to with that thought process and why, however you are in essence putting a square peg in a round hole. You are not dealing with cells in a spread sheet, but fields in rows. Datatables are objects that represent tables in a database which have a different structure (and the datagridview control represents the same by extension). Keep in mind that a large part of the design of these objects is to be able to update the database with changes made to the data in the datagrid. You can not in a database table simply delete empty fields in rows and shift data up to fill them as they are distinct records.

Another way to accomplish what you are trying to do would possibly be to use an embeded excel spread sheet instead of a datagridview, provided you aren't trying to go back and update the database and are only looking for output. I've had fairly limited exposure to VSO having done some MS labcasts on the subject. With my limited knowlege of this however I'd view this approach as being more difficult to accomplish, but my limited exposure to working with office documents programatically I'm sure biases away from that approach.

Ok will try and ley u know

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.