使用MultiCombobox时出现问题

使用MultiCombobox时出现问题

本文介绍了使用MultiCombobox时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我使用的是Multicombobox,但有一个问题.

首先,我从数据集中将两列加载到我的multicombobox中
但是当我转到应用程序的另一个模块时,
我返回到多组合框并单击.

它显示带有错误的数据.

我给你一张图片,告诉你错误:



我使用的代码如下:

Hello friends,

I have using a Multicombobox but i have one problem.

first I load two columns into my multicombobox from a data set

but when i go to another module of my aplication and when
i return to the multicombobox and clicked.

it display the data with erros.

I give you a picture that show you the error:



The code i have using is the following:

string sqlqwery = "select vehiculos.cod as codigo,nombre as Nombre from vehiculos,socio where vehiculos.cod_so=socio.cod order by vehiculos.cod asc;";
conexion con = new conexion();
DataSet myDs = new DataSet();
myDs = con.consulta(sqlqwery);
multiColumnComboBox1.DataSource = myDs.Tables[0];
multiColumnComboBox1.DisplayMember = "codigo";
multiColumnComboBox1.ValueMember = "codigo";
multiColumnComboBox1.Refresh();



对于这种情况,请给我任何建议.

注意:

ListBox和ComboBox没有多列支持,因此使用Muliticombobox
您可以在此处查看有关内容:http://www.codeproject.com/KB/combobox/multicolumnlistbox.aspx(错误)
正确的链接是:一个数据绑定的多列组合框 [ ^ ]
但是我使用了这个新控件,却发现了后面提到的问题.
我正在等你的帮助

谢谢,



Please give me any advice for this case.

Note:

the ListBox and ComboBox didn''t have multi-column support, For that reasona using the Muliticombobox
you can see about that here: http://www.codeproject.com/KB/combobox/multicolumnlistbox.aspx (error)
the correct link is it: A data-bound multi-column combobox[^]
But I using this new control, but I found the mentioned problem behind.
Grettings I waiting for your helps

Thanks,

推荐答案

protected override void OnDataSourceChanged(EventArgs e)
{
  base.OnDataSourceChanged(e);
  InitializeColumns();
}


与:


with:

protected override void OnDataSourceChanged(EventArgs e)
{
  InitializeColumns();
  base.OnDataSourceChanged(e);
} 



我不确定为什么现在需要这样做.我是4年前编写的原始代码,目前我没有时间去研究为什么这可能会有所作为.但是无论如何,还是用组合框解决了OP的问题.



I am not sure why that''s needed now. I wrote the original code 4 years ago, and at the moment I don''t have time to dig into why this might make a difference. But anyway that fixed the OP''s problem with the combobox.



the solution is
1) Call begin update method
2) fill the multilistbox with datasource
3) call end update method
like this:
<pre lang="sql">this.multiColumnListBox1.BeginUpdate();
                this.multiColumnListBox1.DataSource = myDs.Tables[&quot;dt&quot;];
                this.multiColumnListBox1.EndUpdate();</pre>


这篇关于使用MultiCombobox时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 01:27