Need to delete row from datagrid

from the data set,

VB.NET:
[size=2]SqlDataAdapter1.SelectCommand.CommandText = _

"Select programID as [Program ID], rateColumn as [Rate Column], lock10 as [Lock 10], lock25 as [Lock 25], lock40 as [Lock 40], " & _
"lock55 as [Lock 55], rowStart as [Row Start], rowEnd as [Row End] " & _
"From myMort.dbo.tblConfiguration"

DataSet1.Clear()

SqlDataAdapter1.Fill(DataSet1, "display")

DataGrid1.SetDataBinding(DataSet1, "display")
[/size]
 
Note that the data in a bound DataGrid does not actually correspond directly to the data in the DataTable it was bound to. Rather, it corresponds to the data exposed by the table's DefaultView property, which is a DataView. For this reason, if the RowFilter, RowStateFilter or Sort properties of the DataView have been set or the AllowSorting property of the DataGrid is True, the row at any particular index in the DataGrid may not correspond to the row at the same index in the DataTable. It will, however, correspond to the row at the same index in the DataView. For this reason, you should not delete the row like this:
VB.NET:
DataSet1.Tables("display").Rows(DataGrid1.CurrentRowIndex).Delete()
which is directly from the table, and may be the wrong row, but rather like this:
VB.NET:
DataSet1.Tables("display").DefaultView(DataGrid1.CurrentRowIndex).Delete()
which is from the view and will always be the correct row.
 
Back
Top