I have a Windows Forms application that displays information in a Master-Detail DataGridView, written based on the instructions at https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/create-a-master-detail-form-using-two-datagridviews.
The data is displaying correctly, and selecting rows on the master DataGridView displays the expected data in the details DataGridView.
What I am trying to do is pass in an integer when loading the page so that the DataGridViews will display with the right master row selected and the corresponding detail rows displayed.
So far I can pass in the integer to select the correct Master row, but one still needs to click the row to display the correct details rows.
Here is the constructor for the form:
public PalletList(User user, int orderId)
{
_user = user;
InitializeComponent();
}
In the Load() method, I populate the DGVs and Get Data for them. Then:
foreach (DataGridViewRow row in ordersDataGridView.Rows)
{
if ((int)row.Cells["Id"].Value == orderId)
{
row.Selected = true;
ordersDataGridView.FirstDisplayedScrollingRowIndex = row.Index;
}
}