Wednesday, October 11, 2006

Working with Xceed Cell Editor

In version 3.1 Xceed provided lot of interesting stuff and one of them is Xceed editors. Some most interesting Xceed editors are

Win Combo box
Option Picker

Let get started with how to define a custom cell editor. Let say we have one column that provide description of a data and the column is a multi line supported column. And we want to have custom editor for the description.

First we need to define a cell editor control, for this case this will be a text area, which is a textbox with multiline property set to true. some other property of the textbox also need to set to true for instance AcceptsReturn and WordWrap

//declaration sectionprivate TextBox cellEditorTextBox;

//initialize component

sectioncellEditorTextBox = new TextBox();

cellEditorTextBox.Multiline = true;

cellEditorTextBox.WordWrap = true;

cellEditorTextBox.AcceptsReturn = true;

cellEditorTextBox.Width = 200;cellEditorTextBox.Height = 100;

Now we need to assign the control to the column editor so that when a cell for a column is enter in
edit mode our control can be used to edit the cell. Xcced provide two manager class to deal with cell view and cell edit.
those are

CellEditorManagerCellViewerManager

//assuming that we have have a column named Description
Description.CellEditorManager = new CellEditorManager(cellEditorTextBox,"Text",false,true);

Parameters of CellEditorManager

templateControl
A reference to a Control representing the control that will be used as a template to create the controls that will edit the content of cells.

propertyName
A string representing the property used to get the control's value.
inPlace
true if the Control is painted within the bounds of the cell; false otherwise.

handleActivationClick
Indicates if the control should handle the mouse click once it is activated. Only in the case where inPlace is set to true does it make sense for handleActivationClick to also be set to true.

Defining a WinComboBox

So now we know how to deal with the custom cell editor. may be in some case we need to use a combo box in a xcced data grid to select a value for the cell. we can use custom cell editor for solving the purpose. Some issue need to consider before you actually do the implementation. Case one can be whither all your row need same set of value in the combo box or in case two you need to populate different set of items in the combo box when user enters in edit mode.

If you need only one set then initialize the combo box before assigning to the cell editor manager or if you need different set then you need to subscribe the event of a cell EnteringEdit in the entering edit you can repopulate any item collection you want.

//assuming that we have a column named Name and a win combo box named

//wincombo1private

WinComboBox  NameGridCombo = new WinComboBox();

grid.Columns["Name"].CellEditorManager = new ComboBoxEditor (wincombo1);

Configure row to show Multi line Data

well xceed do support multi line data in there cell for this we need to set some properties of the cell, but one thing must be considered if you have assigned a fixed height to a xceed row this will not work.

//three property must be set for this

Grid.DataRowTemplate.AutoHeightMode = AutoHeightMode.AllContent;

Grid.DataRowTemplate.WordWrap = true;

Grid.DataRowTemplate.FitHeightToEditors = true;

No comments:

Post a Comment