Data Binding of WPF-ComboBox

Source: Internet
Author: User

1. Example 1

Observablecollection <productimg> IMGs = new observablecollection <productimg> (); // set, that is, the data source combobox1.selectedvaluepath = "ID"; // value maintained in the program combobox1.displaymemberpath = "IMG "; // The displayed content combobox1.itemssource = IMGs; // data source combobox1.selectedvalue = 3; // The selected value

2. Bind

// Declare the data context dataclasses1datacontext DB = new dataclasses1datacontext (); List <tbproduct> pros = new list <tbproduct> (); // find the data source var LINQ = (from P in dB. tbproduct select P ). take (10); var linq1 = (from P in dB. tbproclassrelation select P ). tolist (); // bind it to the ComboBox control. This. cbproducttype. itemssource = linq1; this. cbproducttype. selectedvaluepath = "ID"; this. cbproducttype. displaymemberpath = "name ";

 

 

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.