动态组合框选择? [英] Dynamic Combobox Selection?

查看:66
本文介绍了动态组合框选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经动态创建了10个组合框(C0,C1,------,C9),
使用数据源,DisplayMember,ValueMember.


当我要从C0中选择一个值时,另一个C1 ---- C9
价值观也开始受到影响.
如何将每个组合框设置为个人选择?

这是MyCode:

Hi
I have Created 10 Comboboxes(C0,C1,------,C9) Dynamically,
with Datasource,DisplayMember,ValueMember.


When i am going to Select a value From C0, The other C1----C9
Values are also getting effected.
how to make each Combobox as Individual Selection?

Here is MyCode:

private void addcontrols(int num)
{
for (int n = 0; n < num - 1; n++)
{
      cb = new ComboBox();
      cb.Name = "cmbRelationshipDyn" + n;
      cb.Size = new Size(133, 21);
      cb.DropDownStyle = ComboBoxStyle.DropDownList;
      if (n == 0)
      {
      cb.Location = new Point(86, ((n + 1) * 5) + 0);
      }
      else
      {
      cb.Location = new Point(86, ((n) * 35) + 0);
      }
cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
      cb.DataSource = dtrel;
      cb.DisplayMember = "Relationship";
      cb.ValueMember = "ID";
      panel1.Controls.Add(cb);
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{

}




任何机构的帮助将不胜感激.

问候,
Pawan.




Any body''s help would be really appreciated.

Regards,
Pawan.

推荐答案

一些示例代码会有所帮助.但我认为您已将它们都链接到同一来源.通常,例如,您将选择一个名称,并相应地填充其他控件(如果链接正确),因为它们知道数据并注意到更改(实际上,源注意到更改并更新了所有其他控件).但是您现在不想要那样,因此必须为每个组合框分别进行设置.

祝你好运!
Some sample code would help. but I think you linked them all to the same source. Normally you would for example select a name and the other controls are filled accordingly (if linked properly) because they are data aware and notice the change (in reality the source notices the change and updates all other controls). But you don''t want that now, so have to set it up separately for each combobox.

Good luck!


受到影响-你是什么意思?
我看到所有组合框都具有相同的事件处理程序.另外,您将实例化一个组合框对象以处理所有对象.
尝试创建一个组合框数组.但是同样,我不确定您受到感染的确切含义是什么.
By getting affected - What do you mean?
I see that you have the same event handler for all the combo boxes. Also you are instantiating a single combo box object to handle all.
Try creating an array of combo box. But again, I am not sure what exactly you want and what do you mean by getting affected.


我认为每个单独的组合框都可以通过
的sender参数确定 cb_SelectedIndexChanged

除此之外,我认为每个单独的元素都会起作用.
I think each individual combobox can be determined from sender argument of
cb_SelectedIndexChanged

Other than that, each individual element will work I think.


这篇关于动态组合框选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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