Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I bind combox column in the Datagrid
C#
DataGridTemplateColumn textColumn = new DataGridTemplateColumn();
          textColumn.Header = header;
          textColumn.Width = DataGridLength.Auto;
          DataTemplate dts = new DataTemplate();
          FrameworkElementFactory fc = new FrameworkElementFactory(typeof(ComboBox));
          //  Binding b = new Binding("ComboxClass");
          Binding b = new Binding(field);
          b.Mode = BindingMode.TwoWay;
          b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
          fc.SetBinding(ComboBox.ItemsSourceProperty, b);
          // fc.SetValue(ComboBox.DisplayMemberPathProperty, "PriceTypeValue");
          // fc.SetValue(ComboBox.SelectedValueProperty, "PriceTypeId");
          fc.SetValue(ComboBox.DisplayMemberPathProperty, displayMemberPathProperty);
          fc.SetValue(ComboBox.SelectedValueProperty, selectedValueProperty);
          fc.SetValue(ComboBox.SelectedIndexProperty, 0);
          fc.SetValue(ComboBox.WidthProperty, 100.0);

          dts.VisualTree = (fc);

          textColumn.CellTemplate = dts;
          dgForData.Columns.Add(textColumn);


Began to appear normal, when the data more when I scroll down, find combox default selectIndex = 0 data not see (the content is combox empty)

Asked the teacher pointing

Want to ask a question, how do I DataGridComboBoxColumn dynamic binding in code, I can not find accurate information
Posted

try to google let me google that for you...how can work I hope this link may be use full for you.
another link is How to Bind ComboBox in DataGridview Using windows application[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900