本文介绍了附加信息:当控件受数据绑定时,无法以编程方式将行添加到datagridview的rows集合中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 使用System; 使用System.Collections.Generic; 使用System.ComponentModel; 使用System.Data; 使用System.Data.SqlClient; 使用System.Drawing; 使用System.Linq; 使用System.Text ; 使用System.Threading.Tasks; 使用System.Windows.Forms; namespace lllllllll { 公共部分类Form2:表格 { public Form2(字符串Item_no,字符串Item_name,字符串说明,字符串价格) { InitializeComponent(); dataGridView1.Rows.Add(); dataGridView1.Rows [0] .Cells [0] .Value = Item_no; dataGridView1.Rows [0] .Cells [1] .Value = Item_name; dataGridView1.Rows [0] .Cells [2] .Value = Description; dataGridView1.Rows [0] .Cells [3] .Value = P.米; } private void Form2_Load(object sender,EventArgs e) { // TODO:这行代码将数据加载到'dataDataSet1.Items'表中。您可以根据需要移动或移除它。 this.itemsTableAdapter.Fill(this.dataDataSet1.Items); } } } 我尝试过: 使用System; 使用System.Collections.Generic; 使用System.ComponentModel; 使用System.Data; 使用System.Data.SqlClient; 使用System.Drawing; 使用System.Linq; 使用System.Text; 使用System.Threading.Tasks; 使用System。 Windows.Forms; 命名空间lllllllll { 公共部分类Form2:表格 { public Form2(string Item_no,string Item_name,string Description,string Price) { InitializeComponent(); dataGridView1.Rows.Add(); dataGridView1.Rows [0] .Cells [0] .Value = Item_no; dataGridView1.Rows [0] .Cells [1] .Value = Item_name; dataGridView1。行[0] .Cells [2] .Value = Description; dataGridView1.Rows [0] .Cells [3] .Value = Price; } private void Form2_Load(object sender,EventArgs e) { // TODO:这行代码将数据加载到'dataDataSet1.Items'表中。您可以根据需要移动或移除它。 this.itemsTableAdapter.Fill(this.dataDataSet1.Items); } } } using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace lllllllll{ public partial class Form2 : Form { public Form2( string Item_no, string Item_name, string Description,string Price) { InitializeComponent(); dataGridView1.Rows.Add(); dataGridView1.Rows[0].Cells[0].Value = Item_no; dataGridView1.Rows[0].Cells[1].Value = Item_name; dataGridView1.Rows[0].Cells[2].Value = Description; dataGridView1.Rows[0].Cells[3].Value = Price; } private void Form2_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'dataDataSet1.Items' table. You can move, or remove it, as needed. this.itemsTableAdapter.Fill(this.dataDataSet1.Items); } }}What I have tried:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace lllllllll{ public partial class Form2 : Form { public Form2( string Item_no, string Item_name, string Description,string Price) { InitializeComponent(); dataGridView1.Rows.Add(); dataGridView1.Rows[0].Cells[0].Value = Item_no; dataGridView1.Rows[0].Cells[1].Value = Item_name; dataGridView1.Rows[0].Cells[2].Value = Description; dataGridView1.Rows[0].Cells[3].Value = Price; } private void Form2_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'dataDataSet1.Items' table. You can move, or remove it, as needed. this.itemsTableAdapter.Fill(this.dataDataSet1.Items); } }}推荐答案 是吗?该消息的哪一部分没有意义? 您可以手动添加行,使用dgv.Rows [] ...或者您可以将网格绑定到DataSet或DataTable,但你不能同时做到这两点。因此,您必须手动将所有行添加到DGV(耗时且繁琐!),或者您可以将行添加到drig绑定的数据中。Yeah? What part of that message doesn't make sense?You can add rows manually, with dgv.Rows[]... or you can bind the grid to a DataSet or DataTable, but you can't do both. So, you either have to manually add all the rows to the DGV (time consuming and cumbersome!) or you can add the rows to the data that the drig is bound to. 这篇关于附加信息:当控件受数据绑定时,无法以编程方式将行添加到datagridview的rows集合中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 00:11