Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.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# 如何将二维数组分配给datagridview?_C#_Datagridview_Multidimensional Array - Fatal编程技术网

C# 如何将二维数组分配给datagridview?

C# 如何将二维数组分配给datagridview?,c#,datagridview,multidimensional-array,C#,Datagridview,Multidimensional Array,我有6列,其中第一列是textboxcell,其余是复选框。 我想把二维数组的值放到datagrid中 string[,] debugger={{"name","0","0","1","1","0"}}; 0=错误 1=真(我从datagridview属性窗口分配了假值和真值。 当我尝试这个时,它会给我一个格式异常 grdFont.ColumnCount=6; var row = new DataGridViewRow(); row.Cells.

我有6列,其中第一列是textboxcell,其余是复选框。 我想把二维数组的值放到datagrid中

string[,] debugger={{"name","0","0","1","1","0"}};
0=错误 1=真(我从datagridview属性窗口分配了假值和真值。 当我尝试这个时,它会给我一个格式异常

grdFont.ColumnCount=6;
            var row = new DataGridViewRow();
            row.Cells.Add(new DataGridViewTextBoxCell()
            {
               Value = debugger[0] 
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[1]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[2]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[3]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[4]
            });
            row.Cells.Add(new DataGridViewCheckBoxCell()
            {
                Value = debugger[5]
            });
            grdFont.Rows.Add(row);

有没有其他方法可以实现这一点?

0不等于
false
,1不等于
true
。编写函数将这些数字转换为
布尔值:

public bool ConvertNumberToBoolean(int number)
{
    if (number == 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}
将值设置为单元格时使用此功能:

row.Cells.Add(new DataGridViewCheckBoxCell()
{
    Value = ConvertNumberToBoolean(Convert.ToInt32(debugger[1]));
});

这是一个非常基本的实现,但我相信你已经有了这个想法

这可能会有所帮助:你为什么要使用调试器[1]、[2]等?循环进行,因为我正在进行可行性研究,而不是实际应用。我知道visual studio内部的(FalseValue和TrueValue)属性是什么?[链接]