Click here to Skip to main content
15,918,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I want to delete a row from datagrid according to the passed values, for that 1st i need to find at which row all values are matching. For this I have to find the position of a row.Below is the code I am trying to write.

dbcheck = "select * from qpoo where pono='" & txtpono.Text & "' and itemcode='" & ComboBox1.SelectedItem & "' and serialno='" & txtserialno.Text & "'"
     Dim da As New SqlCeDataAdapter
     Dim ds As New DataSet
     da = New SqlCeDataAdapter(dbcheck, cn)
     da.Fill(ds, "qpoo")
     If ds.Tables("qpoo").Rows.Count = 0 Then
         MsgBox("Scanned item is not present")
         txtserialno.Text = ""
     Else
         dr(0) = txtpono.Text
         dr(1) = ComboBox1.SelectedItem
         dr(2) = txtserialno.Text
         Table1.Rows.Remove(dr)
     End If


Any help is kindly appreciated.

Thanks in advance.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 30-Mar-11 23:02pm
v2

1 solution

Hi to find some value use your underlying data source than searching in a UI element. To search your value you can use Filter expressions in your data table or else the Find method on the DataRow collections. Here is an example how to find using the select method on the data table

C#
DataRow[] rows=dt.Select("ProductName='Product1'");
foreach(DataRow row in rows)
{
    dt.Rows.Remove(row);
}


(I hope this simple code snippet is not difficult for you to convert to vb.net). The key is just the select method.

where dt refers to a data table.Bind the filtered table to the data grid. If you want to remove those rows from the database then get the ids from the filtered rows and construct the delete query.

Even better way create a new DataView and use its RowFilter which has same syntax as this select method and bind the dataview to the grid. So your original datatable is unaffected. Choice is yours.
 
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