Thursday, October 12, 2006

Xceed Grid Check box Column and Single Click Edit

In some cases we need to put a column with check box, so that we can select some row with check box. And then perform some operation depending on check box value. Xceed provide a very simple and easy way to accomplish this task. All you need to do is to add a column and set is data type to bool that’s it you are done.


grid.Columns.Add( new Column( "CHECKBOX", typeof( bool ) ) );

grid.Columns["CHECKBOX"].Title = "";

grid.Columns["CHECKBOX"].Width = 100;

grid.Columns["CHECKBOX"].Fixed = true;//XceedGrid 3.1


Now how do you set or get checked state from the column. Well when creating a new data row you simple put true or false to the value of the cell. If you assign false the checkbox will be unchecked and vice versa.


//setting values

Xceed.Grid.DataRow row = this.grid.DataRows.AddNew();

row.Cells["CHECKBOX"].Value = false;

foreach(DataRow row in grid.DataRows)

if((bool)row.Cells["CHECKBOX"].Value == true)


//do some work


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


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

Parameters of CellEditorManager

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.

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

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


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;

Tuesday, October 10, 2006

Dynamically Change Xceed Grid Column Title

Dynamically Change Xceed Grid Column Title

Some time we do require changing the column title at run time. During working one of my projects I was assigned a task where I need to add column dynamically and then change that is delete or rename the dynamically added columns. Since you can not edit the Xceed grid header by default the task is a little bit streaky.

You can use context menu or direct edit in the header. For this you need to set some properties of the fixed header row of the Xceed grid. The properties are…


You can use mouse down event to set the property and then edit the column title.
For this you have to subscribe three event of the column

1. Mouse Down event
2. Leaving Edit
3. Edit Left

In the mouse down event you need to set the properties so that the header cell of the column can be edited.

Code Example:

///mouse down

codeColumnManagerRow colManRow =

( ColumnManagerRow )grid.FixedHeaderRows[ 0 ];

columnManagerRow1.AllowColumnReorder = false;

colManRow.Cells[customColumnName].ReadOnly = false ;

colManRow.CanBeCurrent = true;

Xceed.Grid.Cell cell = (Xceed.Grid.Cell)sender;cell.EnterEdit ();

After this the header cell is ready to edit and will enter in edit mode. And you can edit whatever you life. Now the validation or saving part… if you need to validate any stuff regarding the name of the column that is title of the column you can validate the test in leaving edit event.

After leaving edit event we need to set the defaults back to the header cell.

Code Example:

///Edit left

ColumnManagerRow colManRow = ( ColumnManagerRow )grid.FixedHeaderRows[ 0 ];

columnManagerRow1.AllowColumnReorder = true;

colManRow.Cells[customColumnName].ReadOnly = true;

colManRow.CanBeCurrent = false;

In xceed 3.1 cell editors are changed a lot. xcced introduced a two manager for the editing and viewing
purpose. those are cellEditorManger and cellViewerManager. if you have a custom cellEditor. and you have subscribed
the cellEditorManger.Validation event you need to put check in cellEditorManger.
Validation event whether the cell is a datacell or header cell. Other wise it will give a crash
and the edit left event will not be fired….

Code Example:


if(grid.CurrentRow is Xceed.Grid.DataRow){

//perform validation here