UZIERSKI UZIERSKI - 1 month ago 12
C# Question

SelectedRows and DataBoundItem cannot be used like a method c#

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]);