DataGridView将行添加到现有DataGridView时出现问题 [英] DataGridView Problems adding row to existing DataGridView

查看:70
本文介绍了DataGridView将行添加到现有DataGridView时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试用行填充DataGridView。 DGV被添加到表单中,并且监视表示它不为空。

I am trying to fill a DataGridView with rows. The DGV is added to the form and as watch says it is not null.

我的DGV的名称是dgvHives,它在OnLoad中初始化如下:

The name of my DGV is dgvHives and it is initialized in OnLoad like this:

我尝试添加这样的新行:

I try to add a new Row like this:

dgvHives.Rows.Add(CreateHiveItem(hive);

dgvHives.Rows.Add(CreateHiveItem(hive);

但它显示以下错误:

System.Windows.Forms.dll中发生类型为"System.InvalidOperationException"的未处理异常

您只能添加包含列的行,列必须首先创建。

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
You can add only rows which contains columns, the columns has to be created first.

但该行包含列,我通过观看dgvr来检查它。一些提示?

干杯,Ingo


推荐答案

您好

除非您将列添加到dgvHives 在Designer中,您需要在尝试添加行之前添加它们。

Unless you added columns to the dgvHives  in the Designer, you will need to add them before trying to add rows.


这篇关于DataGridView将行添加到现有DataGridView时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆