本文介绍了窗口形式,数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Form,它正在计算和显示我正在使用的TexBox es中的数据,用于进一步计算,现在在保存Button Click上,我有这段书面代码:

I have a Form which is calculating and displaying data in TexBoxes which I''m using for further calculation, now on Save Button Click I have this written code:

DataTable dt = new DataTable();
DataRow drow  = dt.NewRow();
DataColumn dc = new DataColumn("X", typeof(System.String));
DataColumn dc1 = new DataColumn("Y", typeof(System.String));
DataColumn dc2 = new DataColumn("Z", typeof(System.String));
dt.Columns.Add(dc);
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
string[] rows = { "" + textBox10.Text, "" + textBox11.Text, "" + textBox12.Text };
dt.Rows.Add(rows);
dataGridView1.DataSource = dt;


一切正常,只是我希望每次将值保存到新行时都保存而不覆盖先前的行,如:
r1 11 111 111
r2 22 11 1111
...
etc


It is working fine except that I want on save each time value gets saved to new row without overwriting the previous like:
r1 11 111 111
r2 22 11 1111
...
etc

推荐答案


string[] rows = { "" + textBox10.Text, "" + textBox11.Text, "" + textBox12.Text };
dt.Rows.Add(rows);


BindGrd();
4. BindGrid()

公共无效dataGridView1.DataSource = dt;


BindGrd();
4. BindGrid()

public void dataGridView1.DataSource = dt;


这篇关于窗口形式,数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:55