首页 文章

如何以编程方式将行插入DataGridView?

提问于
浏览
1

我试图以编程方式将一行插入DataGridView . 列是:

Column1组合框Column2文本框

这是我的代码 . Column1使用DataGridView的内置DataSource绑定到表 .

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

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

但是这给了我一个“DataGridViewComboBoxCell无效值”的错误 . 我该如何解决?

1 回答

  • 2
    DataGridViewRow dr = new DataGridViewRow();
    DataGridViewCell dcDescription = new DataGridViewTextBoxCell();
    
    dcDescription.Value = "some text";
    
    dr.Cells.Add(dcDescription);
    dataGridViewDoctorEventsAddServices.Rows.Add(dr);
    

相关问题