In Silverlight, set the current selection, data binding, and values for ComboBox.

Source: Internet
Author: User
Public partial class page: usercontrol {public page () {// The initializecomponent () variable needs to be initialized; cmbs_items_add () ;}public class combitem {public string value {Get; set ;} public String text {Get; Set ;}/// <summary> /// assign a value to combox /// </Summary> private void cmbs_items_add () {// assign this to the house id. CMBS. updatelayout (); // set this. CMBS. updatelayout (); ensure that all sub-object locations of the uielement are correctly configured with the layout update list <combitem> CTG = new list <combitem> () {New combitem {value = "", TEXT = ""}, new combitem {value = "0", text = "normal"}, new combitem {value = "1", text = "new "}, new combitem {value = "2", text = "split" }}; this. CMBS. itemssource = CTG; CMBS. displaymemberpath = "text"; // bind the text value this. CMBS. selectedvaluepath = "value "; // specify the value} # region ========= set the current selection item ======= combitem EMP = new combitem () {value = "", text = ""}; // This. combobox1.selecteditem = EMP; // This setting does not work. list <combitem> List = This. CMBS. itemssource as list <combitem>; int flag =-1; for (INT I = 0; I <list. count; I ++) {If (list [I]. value = EMP. value & list [I]. TEXT = EMP. text) {flag = I; break;} This. CMBS. selectedindex = flag; # endregion // obtain the combox selected value combitem EMP = This. CMBS. selecteditem as combitem ;}

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.