简体   繁体   English

组合框短路未将键入的值放在前面

[英]Combobox shorting not bringing the typed value to front

I have two combobox one is product Id and another one is product name. 我有两个组合框,一个是产品ID,另一个是产品名称。 For the both combobox I am assigning same DataTable as datasourse. 对于这两个组合框,我都将相同的DataTable分配为datasourse。

My combobox proprieties are follows 我的组合框属性如下

cmbprID.DataSource = prdList;
cmbprID.DisplayMember = "PRD_ID";
cmbprID.ValueMember = "PRD_ID";

cmbprName.DataSource = prdList;
cmbprName.DisplayMember = "PRD_NAME";
cmbprName.ValueMember = "PRD_NAME";

and AutoComplete mode=None 并且自动完成模式=无

 Sorted=false

And now when I run the program all the data loading properly. 现在,当我运行程序时,所有数据都将正确加载。 When I tried to type it is shorting the data but some times some of the data not bring to front. 当我尝试键入时,它正在缩短数据,但有时某些数据没有显示出来。 But that data available in drop down. 但是该数据在下拉列表中可用。

Following steps I took to solve 按照我采取的步骤解决

  • Shorted=true; Shorted = true;

For this every thing is working fine. 为此,一切正常。 But the problem is, it is not picking product name with respect to PID which I select. 但是问题是,它不是针对我选择的PID选择产品名称。 The reason is the combobox sorting the data so the index value getting change. 原因是组合框对数据进行排序,因此索引值会发生变化。

  • ORDER BY PRODUCT_ID ASC in my SQL query. 我的SQL查询中的ORDER BY PRODUCT_ID ASC。

Even this also not working. 即使这样也行不通。 But it accuracy is better initial stage. 但是它的准确性在初期是更好的。

cmbprName.DisplayMember = "PRD_NAME";
cmbprName.ValueMember = "PRD_ID";
cmbprName.Sorted=true;

But no use 但是没用

Please help me to get of of it 请帮助我

I would use Shorted=true; 我会用Shorted=true; with ValueMember set with ID rather than same display member. ValueMember设置为ID而不是同一显示成员。 then you can get the selected text and the value from same combobox. 那么您可以从同一组合框中获取选定的文本和值。

cmbprName.DataSource = prdList;
cmbprName.DisplayMember = "PRD_NAME";
cmbprName.ValueMember = "PRD_ID";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM