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…

ReadOnly
CanBeCurrent

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:

///cellEditorManger.validation

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

//perform validation here

}

No comments:

Post a Comment