• DevExpress中 的DataGrid每一行根据其类型显示控件的种类


    public class ValueSelector : DataTemplateSelector
    {
    public ValueSelector()
    {
    }
    bool IsScrollMove = false;
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
    DataTemplate dt = new DataTemplate();
    EditGridCellData cellDatas = item as EditGridCellData;
    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)
    {
    TaggedValueModel taggedValueModel = cellDatas.RowData.Row as TaggedValueModel;
    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")
    {
    int indexId = dicData[taggedValueModel.Property].LastIndexOfAny(new char[] { '=' });//找到最后一个等号的索引号
    string strProperty = dicData[taggedValueModel.Property].Substring(indexId + 1);
    string[] listPropertyValue = strProperty.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
    taggedValueModel.ValueList = listPropertyValue.ToList();//获取数据
    //实例化下拉列表框控件
    FrameworkElementFactory comboBoxEdit = new FrameworkElementFactory(typeof(ComboBoxEdit));
    comboBoxEdit.SetBinding(ComboBoxEdit.ItemsSourceProperty, new Binding()
    {
    Path = new PropertyPath("RowData.Row.ValueList"),
    Mode = BindingMode.OneTime,
    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
    });
    comboBoxEdit.SetValue(ComboBoxEdit.MarginProperty, new Thickness(0));
    comboBoxEdit.SetValue(ComboBoxEdit.BorderThicknessProperty, new Thickness(0));
    comboBoxEdit.SetValue(ComboBoxEdit.EditValueProperty, "UNDEFINED");
    comboBoxEdit.SetValue(ComboBoxEdit.IsTextEditableProperty, false);
    dt.VisualTree = comboBoxEdit;
    }
    else if (dicType.ContainsKey(taggedValueModel.Property))
    {
    int DH_indexId = dicData[taggedValueModel.Property].LastIndexOfAny(new char[] { '=' });//找到最后一个等号的索引号
    int FH_indexId = dicData[taggedValueModel.Property].LastIndexOfAny(new char[] { ';' });//找到最后一个分号的索引号
    string strProperty = dicData[taggedValueModel.Property].Substring(DH_indexId + 1, FH_indexId - DH_indexId - 1);
    if (dicType[taggedValueModel.Property] == "Decimal")
    {
    try
    {
    taggedValueModel.Value = Convert.ToDecimal(strProperty).ToString("N4");
    }
    catch (Exception)
    {
    taggedValueModel.Value = "";
    }
    }
    else if (dicType[taggedValueModel.Property] == "Const")
    taggedValueModel.Value = strProperty;
    //else
    // taggedValueModel.Value = "";
    ////实例化文本控件
    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
    txtBox.SetBinding(TextBox.TextProperty, new Binding()
    {
    Path = new PropertyPath("RowData.Row.Value"),
    Mode = BindingMode.OneTime,
    UpdateSourceTrigger = UpdateSourceTrigger.Default
    });
    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.Black);
    txtBox.SetValue(TextBox.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
    txtBox.SetValue(TextBox.BorderThicknessProperty, new Thickness(0));
    dt.VisualTree = txtBox;
    }
    else
    {
    //实例化文本控件
    FrameworkElementFactory txtBox = new FrameworkElementFactory(typeof(TextBox));
    txtBox.SetBinding(TextBox.TextProperty, new Binding()
    {
    Path = new PropertyPath("RowData.Row.Value"),
    Mode = BindingMode.OneTime,
    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
    });
    txtBox.SetValue(TextBox.ForegroundProperty, Brushes.Black);
    txtBox.SetValue(TextBox.BackgroundProperty, new SolidColorBrush(Colors.Transparent));
    txtBox.SetValue(TextBox.BorderThicknessProperty, new Thickness(0));
    dt.VisualTree = txtBox;
    }
    }
    return dt;
    }
    }

  • 相关阅读:
    Python调用C++的DLL
    Go-map
    Go-切片
    Go-数组
    Go-流程控制
    Go-运算符
    Go-变量和常量
    Go-VS Code配置Go语言开发环境
    Go-跨平台编译
    Go-从零开始搭建Go语言开发环境
  • 原文地址:https://www.cnblogs.com/zhaiganggang/p/12344523.html
Copyright © 2020-2023  润新知