本文介绍了如何在dataGrid中绑定combox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在数据网格中绑定combox列 DataGridTemplateColumn textColumn = new DataGridTemplateColumn(); textColumn.Header = header; textColumn.Width = DataGridLength.Auto; DataTemplate dts = new DataTemplate(); FrameworkElementFactory fc = new FrameworkElementFactory( typeof (ComboBox)); // 绑定b =新绑定(ComboxClass); 绑定b = new 绑定(字段); 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); 开始显示正常,当我向下滚动数据时,找到combox默认的selectIndex = 0数据看不到(内容是combox为空) 问老师指点 想问一个问题,怎么样我在代码中使用DataGridComboBoxColumn动态绑定,我找不到准确的信息解决方案 I bind combox column in the DatagridDataGridTemplateColumn 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 pointingWant to ask a question, how do I DataGridComboBoxColumn dynamic binding in code, I can not find accurate information 解决方案 这篇关于如何在dataGrid中绑定combox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 09:04