本文介绍了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

推荐答案


table.Columns.Add("Cost", typeof(decimal));
            foreach (DataRow row in table.Rows)
            {
                row["Cost"] = 100;
            }




希望对您有帮助




Hope this helps


这篇关于C#DataGridView问题填充列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:46