views:

119

answers:

2

I want to delete the current row in a grid only if a specific value exists in a column.

How can I get the details for the current row?

A: 

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)
AMissico
+1  A: 

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.

ileon