Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在所有选项卡页选项卡上设置DataGridViewCheckBoxCell_C#_Tabcontrol_Datagridviewcheckboxcell - Fatal编程技术网

C# 在所有选项卡页选项卡上设置DataGridViewCheckBoxCell

C# 在所有选项卡页选项卡上设置DataGridViewCheckBoxCell,c#,tabcontrol,datagridviewcheckboxcell,C#,Tabcontrol,Datagridviewcheckboxcell,我有一个TabControl,每个TabPage上都有一个DataGridView。DataGridView在列[0]中有一个DataGridViewCheckBoxCell 我想取消选中所有选项卡页的DataGridView的同一行上的DataGridViews复选框 void myDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { int clickedRow = e.RowI

我有一个TabControl,每个TabPage上都有一个DataGridView。DataGridView在列[0]中有一个DataGridViewCheckBoxCell

我想取消选中所有选项卡页的DataGridView的同一行上的DataGridViews复选框

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;
                    }

                }
            }
        }

    }
我只能在单击的选项卡页上访问DataGridView。myDataGrid_CellContentClick事件中的sender对象似乎不包含其他选项卡页

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;
                    }

                }
            }
        }

    }
如何设置其他选项卡页上的复选框

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;
                    }

                }
            }
        }

    }

如果每个选项卡页包含不同的DataGrid,则需要引用相应的网格,选择匹配的行并检查单元格

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;
            }
        }
    }
}
void myDataGrid\u CellContentClick(对象发送者,DataGridViewCellEventArgs e)
{
int clickedRow=e.RowIndex;
int clicked column=e.ColumnIndex;
如果(clickedColumn!=0)返回;
DataGridView myDataGridView=(DataGridView)发送方;
如果(!TogleAllRowSelection)
{
foreach(tabControl1.TabPages中的TabPage myTabPage)
{
DataGridView grd=myTabPage.Controls.OfType().FirstOrDefault();
如果(grd!=null)
{
grd.Rows[clickedRow]。单元格[0]。值=false;
}
}
}
}

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

如果每个选项卡页包含不同的DataGrid,则需要引用相应的网格,选择匹配的行并检查单元格

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;
            }
        }
    }
}
void myDataGrid\u CellContentClick(对象发送者,DataGridViewCellEventArgs e)
{
int clickedRow=e.RowIndex;
int clicked column=e.ColumnIndex;
如果(clickedColumn!=0)返回;
DataGridView myDataGridView=(DataGridView)发送方;
如果(!TogleAllRowSelection)
{
foreach(tabControl1.TabPages中的TabPage myTabPage)
{
DataGridView grd=myTabPage.Controls.OfType().FirstOrDefault();
如果(grd!=null)
{
grd.Rows[clickedRow]。单元格[0]。值=false;
}
}
}
}

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

感谢您的回复,DataGrid类不包含名为Row的属性?谢谢,非常抱歉,但是rows不是vallid属性?错误1“System.Windows.Forms.DataGrid”不包含“Rows”的定义,并且找不到接受“System.Windows.Forms.DataGrid”类型的第一个参数的扩展方法“Rows”(是否缺少using指令或程序集引用?)。但第一个Datagrid也必须更改为DataGridView。我试图编辑,但出现了一个错误。您可以更改它吗?谢谢您的回复,DataGrid类不包含名为Row的属性?谢谢,非常抱歉,Rows不是vallid属性?错误1“System.Windows.Forms.DataGrid”不包含“Rows”的定义,并且找不到接受“System.Windows.Forms.DataGrid”类型的第一个参数的扩展方法“Rows”(是否缺少using指令或程序集引用?)。但第一个Datagrid也必须更改为DataGridView。我试图编辑,但出现了一个错误。你能换一下吗?