I have two DataGridViews with a master-detail relationship. I need to change the current item in both of them programmatically. I tried the following code:
void SetMasterDetailPositions(int masterId, int detailId)
{
var masterPosition = masterBindingSource.Find("id", masterId);
if (0 <= masterPosition)
{
masterBindingSource.Position = masterPosition;
var detailPosition = detailBindingSource.Find("id", detailId);
if (0 <= detailPosition)
{
detailBindingSource.Position = detailPosition;
}
}
}
but I got an exception on this line:
var detailPosition = detailBindingSource.Find("id", detailId);
The exception says:
System.ArgumentException occurred
HResult=0x80070057
Message=DataMember property 'id' cannot be found on the DataSource.
In short, I managed to change the current item in the master grid but not in the detail grid. Why am I getting this exception?
User contributions licensed under CC BY-SA 3.0