[Original] examples of "DataGrid intermediate link dynamic binding parent/child ComboBox" in Silverlight ., Datagridcombobox

Source: Internet
Author: User

[Original] examples of "DataGrid intermediate link dynamic binding parent/child ComboBox" in Silverlight ., Datagridcombobox

I tried many solutions. Due to the uncertainty of the Name of the parent and child comboBox in each row dynamically generated by the Datagrid, it is difficult to obtain the child ComboBox from the parent ComboBox binding event according to the Name.

I spent a lot of time discussing with my colleagues. The final solution is as follows:

Note: Parent and Child combobox representatives: main industry/sub-Industry

Private void upload (object sender, SelectionChangedEventArgs e) {ComboBox combobox = sender as ComboBox; // obtain another conbox control CurrentRowIndusrtylist = (sender as ComboBox); if (CurrentRowIndusrtylist! = Null ){DataGridCell dg= (Maid) (CurrentRowIndusrtylist. Parent); // Key UsageIf (maid. GetRowContainingElement (dg )! = Null ){CurrentRowIndusrtySublist= This. Maid [3]. GetCellContent (maid. GetRowContainingElement (dg) as ComboBox; // Key UsageIf (CurrentRowIndusrtySublist! = Null)BindSubIndusrtyCodes (); // dynamically bind the child combobox}}} Private void BindSubIndusrtyCodes () {if (CurrentRowIndusrtylist. SelectedItem! = Null) {var unitIndusrtyItem = CurrentRowIndusrtylist. selectedItem as System_IndustryCodes; _ db. load (_ db. getIndustryCodesQuery (), op => {CurrentRowIndusrtySublist. items. clear (); CurrentRowIndusrtySublist. items. add (new System_IndustryCodes {ID =-1, IndustryCodes = "-- select a sub-Industry --"}); IEnumerable <System_IndustryCodes> tempsubList = op. entities. where (q => q. parentCodeID = unitIndusrtyItem. ID); fore Ach (var temp in tempsubList) {if (temp = null) return; CurrentRowIndusrtySublist. items. add (new System_IndustryCodes {ID = temp. ID, IndustryCodes = temp. industryCodes});} CurrentRowIndusrtySublist. displayMemberPath = "IndustryCodes"; CurrentRowIndusrtySublist. selectedValuePath = "ID"; CurrentRowIndusrtySublist. updateLayout (); if (CurrentRowIndusrtySublist. items. count = 1) CurrentRowIndusrtyS Ublist. SelectedIndex = 0; else CurrentRowIndusrtySublist. SelectedIndex = 1; // if (_ OldSubindustryId! = 0) // CurrentRowIndusrtySublist. selectedItem = (from q in CurrentRowIndusrtySublist. items where (q as System_IndustryCodes ). ID = _ OldSubindustryId select q ). firstOrDefault (); // Default Option-Sub-industry}, null );}}

 

Final effect:

Related Article

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.