简体   繁体   中英

Combobox shorting not bringing the typed value to front

I have two combobox one is product Id and another one is product name. For the both combobox I am assigning same DataTable as 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;

For this every thing is working fine. But the problem is, it is not picking product name with respect to PID which I select. The reason is the combobox sorting the data so the index value getting change.

  • ORDER BY PRODUCT_ID ASC in my SQL query.

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; with ValueMember set with ID rather than same display member. then you can get the selected text and the value from same combobox.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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