is there a way to cast/convert the currently selected Row in a datagridview to a custom Object?
For example, I’m trying to cast the selected row to an object of type Client, however, I am unable to do so using this method.
DataGridViewSelectedRowCollection rows = dgvClient.SelectedRows;
foreach (DataGridViewRow r in rows)
{
DataRow myRow = (r.DataBoundItem as DataRowView).Row;
Client current = (Client)myRow;
}
You can also use implicit and explicit operator
for eg
similarly you could overload implicit. With implicit operator you the conversion would take automatically with out casts