I have a tabcontrol with two tabpages.
At each there is a datagridview.
They have the same binding source.
I have a problem with sync selectedrows on each.
Now, I have :
private void dgvGeoObjectsSecondView_SelectionChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 1)
{
foreach (DataGridViewRow dvRow in this.dgvGeoObjectsSecondView.Rows)
{
foreach (DataGridViewRow dvRowFirstView in this.dgvGeoObjectsFirstView.Rows)
{
if ((long) ((DataRowView) dvRow.DataBoundItem)["ObiektID"] ==
(long) ((DataRowView) dvRowFirstView.DataBoundItem)["ObiektID"])
dvRowFirstView.Selected = dvRow.Selected;
}
}
}
}
private void dgvGeoObjectsFirstView_SelectionChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex==0)
{
foreach (DataGridViewRow dvRow in this.dgvGeoObjectsFirstView.Rows)
{
foreach (DataGridViewRow dvRowSecondView in this.dgvGeoObjectsSecondView.Rows)
{
if ((long)((DataRowView)dvRow.DataBoundItem)["ObiektID"] ==
(long)((DataRowView)dvRowSecondView.DataBoundItem)["ObiektID"])
dvRowSecondView.Selected = dvRow.Selected;
}
}
}
}
But, when I'm changing tabpage selectedrows in second grid are clearing.
Any ideas, or experience with this problem?开发者_如何学JAVA
It could be due to the fact that binding is nonfunctional until the control first becomes visible. The workaround is to make the second grid temporarily visible.
精彩评论