使用MultiCombobox时出现问题 [英] Problem using MultiCombobox

查看:72
本文介绍了使用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,

推荐答案

我将其添加为答案,以便其他任何访问此线程的人都知道发生了什么,而无需查看所有注释.

OP正在使用我的多列组合框类以及其他人的多列列表框类.他为列表框问题启动了一个单独的线程.但是我班上的解决方法是这样做:

替换:

I''ll add this as an answer so anyone else visiting this thread knows what happened without going through all the comments.

The OP was using my multi-column combobox class as well as someone else''s multi-column listbox class. He''s started a separate thread for the listbox problem. But the fix to my class was to do this:

Replace:

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.


这些链接是MultiColumn列表框的最佳选择之一
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.multicolumn.aspx [ ^ ]
These link the one of best for MultiColumn listbox
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.multicolumn.aspx[^]


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时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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