Datatable and Grid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have created a datatable and bind it to my datagrid1 to

how can i delete rows by content

for exampl
i have 3 column test1 test2 test3 with a number of rows, lets say 5
in one of these cells of column TEST2 there is a value of "BET" in it
How can i find it and delete that row

Thanks
 
Create a DataView and Bind the grid to it (I'm assuming you want to do this
programatically, not just filter it so only BET shows and the user then
deletes it via the ui)

Ok, so you have a datatable dt
DataView dv = dt.DefaultView;
DataGrid1.DataSource = dt;


Ok, so no we have the thing bound to the view instead of the datatable.
Object[] searchValue = new Object[1];
dv.Sort = "Test2";
searchValue[0] = "BET";
int i = dv.Find(searchValue);
dt.Rows.Delete();

If you want more values to find, then just change the size of the arrray and
then add the additional values.

Now, if you wanted to just show the Row(s) with BET, in the grid, you could
just set the RowFilter.. dv.RowFilter = "Test2 = BET" ; and then the grid
would now only show the Row or rows with BET in Test2.

Does this help?
 
I was able to delete the rows , but the issue now is after deleting a row or many the program stops responding. Sometime i get an error System.IndexOutOfRangeException: There is no row at position -1

DataView dv = orderTable.DefaultView
Object[] searchValue = new Object[1]
dv.Sort = "ID"
string test = (oStat.RemoteOID.ToString ())
searchValue[0]=(test)
int i = dv.Find(searchValue)
orderTable.Rows.Delete()

Any sugestion
Thank You
 
Back
Top