本帖最后由 CanYou8 于 2016-5-14 11:27 编辑
在WPF C1FlexGrid的CellFactory中重写了CreateCellContentEditor方法,以便给需要的单元格绑定下拉框
- /// <summary>
- /// 重写 单元格编辑模板
- /// </summary>
- public override void CreateCellContentEditor(C1FlexGrid grid, Border bdr, CellRange range)
- {
- base.CreateCellContentEditor(grid, bdr, range);
- // get row/col
- var row = grid.Rows[range.Row];
- var col = grid.Columns[range.Column];
- if (null == row.DataItem) return;
- var model = row.DataItem as ParamModel;
- if (null == model) return;
- // 参数值列的控制
- if (_isReadOnly || col.ColumnName != "ParamValue") return;
- //绑定部分参数值列为下拉框
- if (!string.IsNullOrEmpty(model.MembersCollection))
- {
- var arr = model.MembersCollection.Split(',');
- if (arr.Any())
- {
- _paramValueList.Clear();
- foreach (string i in arr)
- {
- _paramValueList.Add(new { value = i, name = i });
- }
- }
- C1ComboBox comboBox = new C1ComboBox();
- comboBox.VerticalAlignment = VerticalAlignment.Center;
- comboBox.HorizontalAlignment = HorizontalAlignment.Center;
- comboBox.SetResourceReference(C1ComboBox.StyleProperty, "Grid-AutoComboBox-List");
- comboBox.Margin = _emptyThickness;
- comboBox.Watermark = string.Empty;
- comboBox.Width = 120;
- comboBox.DisplayMemberPath = "name";
- comboBox.SelectedValuePath = "value";
- comboBox.ItemsSource = _paramValueList;
- Binding binding = new Binding();
- binding.Path = new PropertyPath("ParamValue");
- binding.Mode = BindingMode.TwoWay;
- comboBox.SetBinding(C1ComboBox.TextProperty, binding);
- comboBox.IsDropDownOpen = true;
- bdr.Margin = _emptyThickness;
- bdr.Padding = _emptyThickness;
- bdr.Child = comboBox;
- }
- }
复制代码 在xaml文件中定义C1FlexGrid
- <c1:C1FlexGrid Name="c1FlexGrid" ItemsSource="{Binding List,IsAsync=True}"
- PreviewKeyDown="c1FlexGrid_PreviewKeyDown"
- LoadedRows="c1FlexGrid_LoadedRows"
- SelectionChanged="c1FlexGrid_SelectionChanged">
- <c1:C1FlexGrid.Columns>
- <c1:Column Header="参数值" Width="5*" Binding="{Binding ParamValue, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
- </c1:C1FlexGrid.Columns>
- </c1:C1FlexGrid>
复制代码 但是当提示参数值必填时,下拉选择的效果就没有了,请问如何解决这个问题?
|