Get the details of the current row when using a typed dataset/binding source in a winforms application
I want to delete the current row in a grid only if a specific value exists in a c开发者_开发技巧olumn.
How can I get the details for the current row?
The following code does what you want:
// Get the context.
BindingContext context = myGrid.BindingContext;
// Get the currency manager.
BindingManagerBase manager = context [myDataset, "MyTable"];
// Get the current row view.
DataRowView rowView = (DataRowView) manager.Current;
// Assume you have a bit field and want to get its value
bool flag = (bool) rowView ["MyBitField"];
Hope this helps.
Access the CurrentRow's (DataGridViewRow) Cells or DataBoundItem items, depending on your needs. You will have to cast the DataBoundItem object to your strongly-typed data row.
Dim oRow As FooDataRow = DirectCast(CurrentRow.DataBoundItem, FooDataRow)
精彩评论