请问我如何让每个组合框都显示下载的价值。 [英] Please How Wil I Make Each Combo Box Will Show A Dropdown Of The Value Fetched.

查看:60
本文介绍了请问我如何让每个组合框都显示下载的价值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问如何在datagridview中实现这一点,当从数据库中获取数据时,每个组合框将显示它所获取的值的下拉列表。



一个实例,如果x得到10,12,15,9,5,3

第一个组合框会显示一个下拉列表1到10,第二个将显示1到12,...





DataGridViewComboBoxColumn dv = new DataGridViewComboBoxColumn();

dv.HeaderText =myCombobox;



cmd.Connection = conn;

cmd.CommandType = CommandType.Text ;

cmd.CommandText =Select * from Toolz;

conn.Open();

reader = cmd.ExecuteReader();

while(reader.Read())

{

x = Reader.GetInt32(3);

}

foreach(dataGridViewRow dvx in dataGridView3.Rows)

{

y = Convert.ToInt32(dvx.Cells [3] .Value.ToString() };

}

{g = 0; g< Ÿ; g ++};

List< int> xl = new List< int>();

xl.Add(g);



foreach(dataGridViewColumn dvx in dataGridView3.Rows)

{

dv.Items.Add(xl);

}

解决方案

< blockquote>看看这里:

数据绑定Windows窗体ComboBox或ListBox控件 [ ^ ]

ComboBox数据绑定示例 [ ^ ]


Please how can I achieve this in a datagridview that when data is fetched from database, that each combo box will show a dropdown of the value it has fetched.

for an instance, if x gets 10,12,15,9,5,3
the first combobox will show a dropdown of 1 to 10, the second will show 1 to 12,...


DataGridViewComboBoxColumn dv = new DataGridViewComboBoxColumn();
dv.HeaderText = "myCombobox";

cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from Toolz";
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
x = Reader.GetInt32(3);
}
foreach (DataGridViewRow dvx in dataGridView3.Rows)
{
y = Convert.ToInt32(dvx.Cells[3].Value.ToString());
}
for {g = 0; g < y; g++} ;
List<int> xl = new List<int>();
xl.Add(g);

foreach (DataGridViewComboBoxColumn dvx in dataGridView3.Rows)
{
dv.Items.Add(xl);
}

解决方案

Have a look here:
Data Binding a Windows Forms ComboBox or ListBox Control[^]
ComboBox Databinding Sample[^]


这篇关于请问我如何让每个组合框都显示下载的价值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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