开发者

SelectedRows the same for two datagridview

开发者 https://www.devze.com 2023-02-24 16:59 出处:网络
I have a tabcontrol with two tabpages. At each there is a datagridview. They have the same binding source.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号