[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: