/// <summary> /// Sets the content of a <see cref="T:System.Windows.Controls.Border" /> element used to display the value of a data /// cell. /// </summary> /// <param name="grid"> /// <see cref="T:C1.WPF.FlexGrid.C1FlexGrid" /> that owns the cell. /// </param> /// <param name="bdr"> /// <see cref="T:System.Windows.Controls.Border" /> element that contains the header. /// </param> /// <param name="rng"> /// <see cref="T:C1.WPF.FlexGrid.CellRange" /> that specifies the row and column represented by the cell. /// </param> public virtual void CreateCellContentEditor(C1FlexGrid grid, Border bdr, CellRange rng) { Row row = grid.Rows[rng.Row]; Column column = grid.Columns[rng.Column]; GroupRow groupRow = row as GroupRow; if (row.DataItem != null) { DataTemplate template = (column.CellEditingTemplate ?? column.CellTemplate); if (template != null) { bdr.Padding = GetTemplatePadding(bdr.Padding); bdr.Child = GetTemplatedCell(grid, template); return; } } Brush editorForeground = grid.EditorForeground ?? grid.CursorForeground ?? grid.SelectionForeground; Binding binding = column.GetEditBinding(grid.Rows[rng.Row]); if (grid.EditableCollectionView != null && Equals(bdr.DataContext, grid.EditableCollectionView.CurrentAddItem)) { binding = Util.Util.CloneBinding(binding); Util.Util.SetBindingValidation(binding, false); } bool gridHasChildren = grid.GetChildItemsPropertyInfo() != null; Type dataType = column.DataType; if ((groupRow == null || gridHasChildren) && (dataType == typeof (bool) || dataType == typeof (bool?))) { CheckBox cb = new CheckBox(); cb.IsThreeState = dataType == typeof (bool?); cb.HorizontalAlignment = HorizontalAlignment.Center; cb.VerticalAlignment = VerticalAlignment.Center; if (editorForeground != null) { cb.Foreground = editorForeground; } bdr.Child = cb; if (binding != null) { cb.SetBinding(ToggleButton.IsCheckedProperty, binding); } cb.FocusVisualStyle = null; } else { C1FlexComboBox comboBox = new C1FlexComboBox(); comboBox.VerticalAlignment = VerticalAlignment.Center; if (editorForeground != null) { comboBox.Foreground = editorForeground; } bdr.Child = comboBox; Thickness padding = bdr.Padding; Thickness thickness = bdr.Padding; bdr.Padding = new Thickness(padding.Left - 2, 0, thickness.Right - 2, 0); if (binding == null) { object obj = grid[rng.Row, rng.Column]; if (obj != null) { comboBox.Text = obj.ToString(); } } else { comboBox.SetBinding(TextBox.TextProperty, binding); } IEditValueConverter converter = column.ValueConverter as IEditValueConverter; if (converter != null) { comboBox.DropDownItems = converter.Values; comboBox.IsEditable = !converter.Exclusive; } } ApplyCellStyles(grid, grid.Cells, rng, bdr, true); }
private void AddAutoCompleteItems(int row, int col, C1FlexComboBox cmb) { Type type = _grid.Columns[col].DataType.GetNonNullableType(); if (type == typeof (object) || type == typeof (string) || type.IsEnum) { int count = _grid.Rows.Count; var dictionary = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < count && dictionary.Count < 100; i++) { int num = (count + row - i - 1)%count; object o = _grid[num, col]; if (o != null) { dictionary[o.ToString()] = true; } } if (dictionary.Count > 0) { cmb.DropDownItems = dictionary.Keys; cmb.IsDropDownEnabled = false; } } }