UZIERSKI UZIERSKI - 1 month ago 6
Vb.net Question

How to convert this to C# properly?

How Do I convert this line of code to c# properly as the

SelectedRows
and
DataBoundItem
cannot be used like a method.

Dim RecordValue As Int32 = grdList.SelectedRows(0).DataBoundItem.Item(_ValueMember)

Answer

The DataBoundItem is typed as Object, you cannot apply an indexing to this property. Instead if you have binded a DataTable/DataView then you can cast the DataBoundItem to the appropriate object and then, if that class offers indexing you can use indexing

DataRowView rowView = grdList.SelectedRows[0].DataBoundItem as DataRowView;
int recordValue = Convert.ToInt32(rowView[_ValueMember]);