DevExpress中 的DataGrid每一行根据其类型显示控件的种类
Posted zhaiganggang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DevExpress中 的DataGrid每一行根据其类型显示控件的种类相关的知识,希望对你有一定的参考价值。
public class ValueSelector : DataTemplateSelector
{
public ValueSelector()
{
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
DataTemplate dt = new DataTemplate();
List<MDGHelper.Row> list = new List<MDGHelper.Row>();
var mapping = MDGHelper.Mapping[GlobalVariable.IAML_MDGDiagram];
for (int i = 0; i < mapping.TaggedValueTypes.RefData.DataSet.Rows.Count; i++)
{
list.Add(mapping.TaggedValueTypes.RefData.DataSet.Rows[i]);
}
Dictionary<string, string> dicType = new Dictionary<string, string>();
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicType.Clear();
dicData.Clear();
if (item != null && item is EditGridCellData)
{
EditGridCellData cellDatas = item as EditGridCellData;
TaggedValueModel taggedValueModel = cellDatas.RowData.Row as TaggedValueModel;
//Window window = Application.Current.MainWindow;
for (int i = 0; i < list.Count; i++)
{
dicType.Add(list[i].Columns[0].value, list[i].Columns[1].value);
}
for (int i = 0; i < list.Count; i++)
{
dicData.Add(list[i].Columns[0].value, list[i].Columns[2].value);
}
if (dicType.ContainsKey(taggedValueModel.Property) && dicType[taggedValueModel.Property] == "Enum")
{
//实例化下拉列表框控件
FrameworkElementFactory comboBoxEdit = new FrameworkElementFactory(typeof(ComboBoxEdit));
comboBoxEdit.SetBinding(ComboBoxEdit.ItemsSourceProperty, new Binding()
{
Path = new PropertyPath("TaggedValues"),
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
comboBoxEdit.SetValue(ComboBoxEdit.MarginProperty, new Thickness(0));
dt.VisualTree = comboBoxEdit;
}
else
{
//实例化文本控件
FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
txtBox.SetBinding(TextBox.TextProperty, new Binding()
{
Path = new PropertyPath("Property"),
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
txtBox.SetValue(TextBox.ForegroundProperty, Brushes.Black);
txtBox.SetValue(TextBox.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
dt.VisualTree = txtBox;
}
}
return dt;
}
}
以上是关于DevExpress中 的DataGrid每一行根据其类型显示控件的种类的主要内容,如果未能解决你的问题,请参考以下文章
Devexpress 中GridLookUpEdit的实现多列筛选问题。
DevExpress WinForms使用教程:Data Grid - Find Panel模式