Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i am binding the data into data grid,my requirement is clear the specific row data

I am trying to clear the data based on row index from data grid.


any body could you please provide the any solution to me.

What I have tried:

i was seen so many articles but i did n't find any solution.
Posted
Updated 7-Apr-20 23:47pm
Comments
[no name] 8-Apr-20 4:19am    
You need to clear the data from the datasource and refresh the grid.

1 solution

You haven't provided enough information to be given a complete answer, but see the comment from @richard-macCutchan.. "You need to clear the data from the datasource and refresh the grid."
Quote:
i am binding the data into data grid,
..therefore you need to remove the row that you want to clear from the datasource that you are binding to and rebind the grid to that amended datasource.

The trouble is we don't know how you have constructed that datasource.

If you are using something that implements IList (e.g. List<t> or ArrayList, etc) then you can Remove the item from the list, possibly using the Index as the means of identifying which item to remove.

If you are extracting the data from a database then you could use the information from the DataGrid row to work out which criteria to put into a WHERE clause to exclude the row you want to clear.

If you actually want to "clear" the row instead of deleting it, i.e. there will be a blank row in your grid, then you will have to replace the data with blanks in your datasource.

Essentially the flow of what you need to do is (pseudo code, untested)
C#
//Code to clear row i
DataView dv;
dv = (DataView) dataGrid1.DataSource;
// remove a row
dv.Delete(i)
// Rebind the amended data
dataGrid1.DataSource = dv;
Finally here is a link to the DataView documentation DataView Class (System.Data) | Microsoft Docs[^]

If you get stuck then come back with a specific question, and be sure to include the relevant code and information - look to the posting guidelines for that
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900