本文介绍了将新数据添加到临时datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, i有问题,如果你可以帮我请:) i有临时datagridview即时通讯我要添加的应用程序行的新数据 但是它唯一的更新行所以有任何建议请求 这是我的代码 private void button1_Click( object sender,EventArgs e) { dataGridView1.AutoGenerateColumns = true ; DataTable dtb = new DataTable(); dtb.Columns.Add( Column1); dtb.Columns.Add( Column2); dtb.Columns.Add( Column3); DataRow dtr = dtb.NewRow(); dtr [ Column1] = textBox1.Text; dtr [ Column2] = textBox2.Text; dtr [ Column3] = textBox3.Text; dtb.Rows.Add(dtr); dataGridView1.DataSource = dtb; // dataGridView1.DataBind(); } 感谢任何类型的答案... 解决方案 直接在网格内添加值如下这个 dataGridView1.Rows.Add(textBox1.Text,textBox2.Text,textBox3.Text); 谢谢你们为了你的答案, i得到了解决方案,希望有一天对某人有用,,,,, dataGridView1.ColumnCount = 2 ; dataGridView1.ColumnHeadersVisible = true ; dataGridView1.Columns [ 0 ]。名称= name; dataGridView1.Columns [ 1 ]。Name = 年龄; string [] row1 = new string [] {textbox1.tex,texbox2.tex}; object [] rows = new object [] {row1}; foreach ( string [] rowArray in 行) { dataGridView1.Rows.Add(rowArray); } } hello everyone,i have question if you could help me please :)i have temporary datagridview im my application i want to add new data to rowbut its only updating row so is there any way any advice pleasthis is my codeprivate void button1_Click(object sender, EventArgs e) { dataGridView1.AutoGenerateColumns = true; DataTable dtb = new DataTable(); dtb.Columns.Add("Column1"); dtb.Columns.Add("Column2"); dtb.Columns.Add("Column3"); DataRow dtr = dtb.NewRow(); dtr["Column1"] = textBox1.Text; dtr["Column2"] = textBox2.Text; dtr["Column3"] = textBox3.Text; dtb.Rows.Add(dtr); dataGridView1.DataSource = dtb; //dataGridView1.DataBind(); }thanks for any type of answers ... 解决方案 add values directly inside grid like thisdataGridView1.Rows.Add(textBox1.Text,textBox2.Text,textBox3.Text);thank you guys for your answer,i got solution and hope be useful for someone in someday ,,,,,dataGridView1.ColumnCount = 2; dataGridView1.ColumnHeadersVisible = true; dataGridView1.Columns[0].Name = "name"; dataGridView1.Columns[1].Name = "age"; string[] row1 = new string[] {textbox1.tex,texbox2.tex};object[] rows = new object[] { row1 }; foreach (string[] rowArray in rows) { dataGridView1.Rows.Add(rowArray); } } 这篇关于将新数据添加到临时datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 04:27