如何以编程方式在DataGridView中插入一行? [英] How do I insert a row into a DataGridView programmatically?

查看:69
本文介绍了如何以编程方式在DataGridView中插入一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式在DataGridView中插入一行。列为:

I am trying to insert a row into a DataGridView programmatically. The columns are:


Column1组合框

Column1 combobox

Column2文本框

Column2 textbox

这是我的代码。

DataGridViewRow row = new DataGridViewRow();
DataGridViewComboBoxCell __action1 = new DataGridViewComboBoxCell();
DataGridViewTextBoxCell __site = new DataGridViewTextBoxCell();

__action.Value = 1; //1 is id.
__sitetype.Value = "google.com";

,但这给我一个 DataGridViewComboBoxCell无效值的错误。我该如何解决?

but this gives me an error of "DataGridViewComboBoxCell invalid value." How do I fix this?

推荐答案

DataGridViewRow dr = new DataGridViewRow();
DataGridViewCell dcDescription = new DataGridViewTextBoxCell();

dcDescription.Value = "some text";

dr.Cells.Add(dcDescription);
dataGridViewDoctorEventsAddServices.Rows.Add(dr);

这篇关于如何以编程方式在DataGridView中插入一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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