Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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#_Winforms_Datagridview - Fatal编程技术网

C# 从动态datagridview的最后一行删除对象

C# 从动态datagridview的最后一行删除对象,c#,winforms,datagridview,C#,Winforms,Datagridview,我有一个winform datagridview: DataTable table = new DataTable(); table.Columns.Add("Check", typeof(bool)); table.Columns.Add("User", typeof(string)); table.Columns.Add("Path", typeof(string)); table.Columns.Add("Status",

我有一个winform datagridview:

 DataTable table = new DataTable();
        table.Columns.Add("Check", typeof(bool));
        table.Columns.Add("User", typeof(string));
        table.Columns.Add("Path", typeof(string));
        table.Columns.Add("Status", typeof(Image));


        using (RegistryKey root = Registry.LocalMachine.OpenSubKey("SOFTWARE\\xyz"))
        {

            foreach (string keyname in root.GetSubKeyNames())
            {
                using (RegistryKey key = root.OpenSubKey(keyname))
                {
                    if (keyname == sentKeyName)
                    {
                        foreach (string valuename in key.GetValueNames())
                        {
                            if (key.GetValue(valuename) is String)
                            {
                                Image image = Image.FromFile(@"Image1.jpg");

                                table.Rows.Add(false, valuename, key.GetValue(valuename), image);
                            }
                        }
                    }
                }
            }                             
        }
        dataGridView1.DataSource = table;
        dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; 
现在,我在表中放入一个图像和复选框,如上图所示

当我有值时,它可以正常工作,但对于最后一行,它是空的,可以编辑,由复选框和错误图像符号填充

还有一种方法可以使一列成为只读

有什么建议吗


谢谢

您获得了额外的一行,因为您允许用户添加新行。如果要禁用添加新行(并隐藏难看的额外行),请使用以下命令:

dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns["Status"].ReadOnly = true;
要使单列为只读,请执行以下操作:

dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns["Status"].ReadOnly = true;
确保在设置数据源后调用此函数

更新:

目前我无法测试任何东西,但该房产似乎正是您所寻找的,尤其是:

防止错误图形从 在行中显示新记录 当控件允许WUserToAddress时 属性值为true时,还必须 或者显式设置单元格值 为空或您自己的错误图形 控件行的处理程序已加载 事件或设置列单元格模板 属性的实例 DataGridViewImageCell派生类型 使用重写的DefaultNewRowValue 返回null或您自己的属性 错误图形


嗨,谢谢你的快速回复。。但是我想要最后一行,这样用户就可以添加值。。我想隐藏图像。。如果可能的话?。。或者我不得不采取另一种方法。。