I cannot get current row value. How can i do?
bindingSource1.DataSource = LData; (LData is Generic List)
public DataRow currentRow
{
get
{
int position = this.BindingContext[bindingSource1].Position;
if (position > -1)
{
return ((DataRowView)bindingSource1.Current).Row;
}
else
{
return null;
}
}
}
I cannot get current row with :
MessageBox.Show(currentRow["NAME"].ToString());
Getting Err: InvalidCastException, how can i do?
Thanks.
You can’t expect to have
DataRowobjects inbindingSource1.Currentif you’re settingDataSourceto aList<T>instead of to aDataTable. In your casebindingSource1.Currentwill contain an instance of the generic type.I suppose you’re initializing LData like this:
The property should then look like this:
And you could read the value like this (assuming
Nameis a property ofT):Not tested of course, but something like this should work. Use the debugger in the following line to see what the contents of the
Currentproperty are actually like: