首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在所有DataGridViewCheckBoxCell选项卡上设置TabPage

在所有DataGridViewCheckBoxCell选项卡上设置TabPage
EN

Stack Overflow用户
提问于 2015-07-12 08:43:06
回答 1查看 306关注 0票数 1

我有一个TabControl,每个TabPage上都有一个DataGridView。DataGridView列中有一个DataGridViewCheckBoxCell。

我想取消选中位于所有DataGridViewCheckBoxes的DataGridView的同一行上的TabPages。

我只能访问单击的DataGridView上的TabPage。看起来,来自myDataGrid_CellContentClick事件的发送方对象不包含其他TabPages。

如何将checkBox设置在另一个TabPages上。

代码语言:javascript
复制
void myDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        int clickedRow = e.RowIndex;
        int clickedColumn = e.ColumnIndex;
        if (clickedColumn != 0) return;
        DataGridView myDataGridView = (DataGridView)sender;

        if (!ToggleAllRowSelection)
        {
            foreach (TabPage myTabPage in tabControl1.TabPages)
            {
                foreach (DataGridViewRow myRow in myDataGridView.Rows)
                {
                    if (myRow.Index == clickedRow)
                    {
                       ((DataGridViewCheckBoxCell)myRow.Cells[0]).Value = false;
                    }

                }
            }
        }

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-12 08:47:41

如果每个TabPage包含不同的DataGrid,则需要引用适当的网格,选择匹配的行并检查单元格。

代码语言:javascript
复制
void myDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    int clickedRow = e.RowIndex;
    int clickedColumn = e.ColumnIndex;
    if (clickedColumn != 0) return;
    DataGridView myDataGridView = (DataGridView)sender;

    if (!ToggleAllRowSelection)
    {
        foreach (TabPage myTabPage in tabControl1.TabPages)
        {
            DataGridView grd = myTabPage.Controls.OfType<DataGridView>().FirstOrDefault();
            if(grd != null)
            {
                grd.Rows[clickedRow].Cells[0].Value  = false;
            }
        }
    }
}

需要注意的是,这段代码假设每个页面只有一个网格,并且每个网格包含的行数与单击的网格相同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31365983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档