Bug of sorted attribute when ComboBox uses data binding

Source: Internet
Author: User

This bug found when investigating a strange system exception occurs when you select one item in ComboBox,ProgramIn the selectindexchanged event, an error occurs when the user selects to refresh the data. After tracing debugging, it is found that the value of selectedvalue is inconsistent with the selected item.

But why is such a strange error?
After investigation, we found that the ComboBox sorted attribute is set.

Re-testCodeAs follows:

 

1 Private   Void Combobox#selectedindexchanged ( Object Sender, eventargs E)
2 {
3 Datarowview DRV = Combobox1.selecteditem As Datarowview;
4 Label1.text =   String . Format ( " Value: {0 }={ 1 }? " , Combobox1.selectedvalue, DRV. Row [ " ID " ]);
5 }
6
7 Private   Void Frmtest_load ( Object Sender, eventargs E)
8 {
9 Datatable dt =   New Datatable ();
10 DT. Columns. Add ( " ID " , Typeof ( Int ));
11 DT. Columns. Add ( " Name " , Typeof ( String ));
12 DT. Rows. Add ( 1 , " F-1 " );
13 DT. Rows. Add ( 2 , " E-2 " );
14 DT. Rows. Add ( 3 , " D-3 " );
15 DT. Rows. Add ( 4 , " C-4 " );
16 DT. Rows. Add ( 5 , " B-5 " );
17 DT. Rows. Add ( 6 , " A-6 " );
18
19 Combobox1.datasource = DT;
20 Combobox1.valuemember =   " ID " ;
21 Combobox1.displaymember =   " Name " ;
22 }

 

If a-6 is selected in ComboBox, the value of selectedvalue is 1.

In fact, the sorted attribute is set to true. A-6 is shown in the first one, that is, selectedindex is 1.

The test shows that the value of selectedvalue is obtained in the order of row in the original able.

But the value of ID obtained through selecteditem is 6, which is correct. Therefore, the value assignment of selecteditem is correct.

It is estimated that this should be a Microsoft Bug, But it is strange that there are not two errors together, but one is wrong.

Lab environment:

Vs2005 Vista. NET Framework 3.5 SP1 v2.0.50727.3074.

If you have other environments, you can try to see if the same bug exists in the frameworks of other versions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.