C#DataGridView问题填充列

编程入门 行业动态 更新时间:2024-10-17 19:31:35
本文介绍了C#DataGridView问题填充列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以用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问题填充列

本文发布于:2023-11-10 16:19:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DataGridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!