我如何...在datagridview中使用值填充组合框? [英] How do I...populate combobox in datagridview with values?

查看:98
本文介绍了我如何...在datagridview中使用值填充组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只添加到组合框的最后一个值并非所有值,为什么?

注意:我以编程方式将行添加到dgv

我的代码是:

only the last value added to combobox not all values , why??
Note : i adding rows programmatically to dgv
my code is :

connection.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = connection;
            string query = "select * from product_details";
            cmd.CommandText = query;
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {

                dataGridView1.ColumnCount = 2;

                dataGridView1.Columns[0].Name = "barcode";
                dataGridView1.Columns[1].Name = "product name ";
  

                dataGridView1.Rows.Add();

                DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();
                ComboBoxCell.Items.AddRange(new string[] {            (reader["barcode"].ToString()) });
                this.dataGridView1[0, 0] = ComboBoxCell;
                this.dataGridView1[0, 0].Value = (reader["barcode"].ToString());
}
connection.close();
}

推荐答案

尝试

https://www.youtube.com/watch?v=WwaMU2sh3Os [ ^ ]

https ://www.youtube.com/watch?v = kW2oKE_5cIE [ ^ ]

嵌入一个ComboBox中的DataGridView [ ^ ]
Try
https://www.youtube.com/watch?v=WwaMU2sh3Os[^]
https://www.youtube.com/watch?v=kW2oKE_5cIE[^]
Embedding a DataGridView in a ComboBox[^]


你好,



假设你有一个datagridview并且有一个名为
cmbproduct,如果你想绑定数据集中的组合框值,那么

Hello ,

suppose you have one datagridview and there one comboboxcolumn named as
cmbproduct and if you want to bind the combobox value from dataset then
cmbproduct.DataSource = dsproduct.Tables[0].Columns[0].Table.DefaultView;
cmbproduct.ValueMember = "PId";
cmbproduct.DisplayMember = "Pname";



将此代码放在要加载组合框的位置。



谢谢

Animesh


put this code where you want to load the combobox .

thanks
Animesh


这篇关于我如何...在datagridview中使用值填充组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆