是否可以用textbox.text文本填充dataGridView列? 因此,如果我在dataGridView中有一个名为"Cost"的列,并且我的textBox1.Text ="200" 它将用="200"填充所有列"单元格的整个成本"列吗? 这是我获取DataGrid数据的方式:
Is it at all posible to fill a dataGridView Column with say a textbox.text text? So if i have a Column in my dataGridView named "Cost" and my textBox1.Text = "200" It will fill the whole "Cost" Column all the Column Cells with = "200"? This is how I get my Data for the DataGrid:
private void GetData(string selectCommand) { try { string conectioninfo = Properties.Settings.Default.finemanConnectionString; connection = new MySqlConnection(conectioninfo); da = new MySqlDataAdapter(selectCommand, connection); MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(da); dataGridView1.AutoGenerateColumns = false; DataTable table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; da.Fill(table); binder.DataSource = table; dataGridView1.DataSource = this.binder; SetupColumns(table); }现在,列调用Cost将不在BindingSource中,但仍需要将蜜蜂添加到名为"Cost"的单独列中. 任何建议表示赞赏. 感谢
Now The Column call Cost will not be in the BindingSource but still need to bee added into a seperate column called "Cost" Any advice is appreciated. Thanks
推荐答案将新列插入数据表,并将每一行的值设置为0(或任何合适的值.然后将数据库绑定到datagrid. Insert a new column into your datatable, and for each row set the value to 0 (or whatever value is appropriate. THEN bind the database to the datagrid.
您可以手动在表中插入一列,然后像这样设置每行的值: You can insert a column into your table manually, and then set the value of each row like this: table.Columns.Add("Cost", typeof(decimal)); foreach (DataRow row in table.Rows) { row["Cost"] = 100; }
希望对您有帮助
Hope this helps
更多推荐
C#DataGridView问题填充列
发布评论