Friday, December 8, 2006

Implementing Xceed GroupRow and Enabling Row Grouping

Xceed Grid of 3.x Version has a very interesting feature Called Grouping. It allows you to show rows in groups and in a horizontal tree structure. Now let’s discuss about how to implement Xceed grid group feature. Well Xceed grouping feature works on columns that is you must group the rows on a particular column, but you can also use recursive grouping.

To add grouping feature first you need to add a Group Object. And we need to set the property “GroupBy”. “GroupBy” property of Group object takes a string as value which represents a column name of the grid. Bellow in code we have a simple example how to add a group by row.

private Xceed.Grid.Group group;

//in declaration section

//in initialization section

grid.Columns.Add( new Column( "DEPT", typeof( string ) ) );

grid.Columns["DEPT "].Title = "Department";

grid.Columns.Add( new Column( "NAME", typeof( string ) ) );

grid.Columns["NAME"].Title = "Employee Name";

group = new Group();

group.GroupBy = "DEPT";

grid.GroupTemplates.Add( group );


In the above example we have two column name and department. And we want to group employees by department. So groupby property of group object is set to the column name. And last of all you need to add the group object in the grid’s group template and call the update grouping method of the grid to activate the grouping.

Xceed by default adds a group header row. But we can always customize the group header and add our own customized group row. Bellow a simple example is given how to add group header row.

//in declaration section

private Xceed.Grid.GroupManagerRow gmrow;

//in initialization section

gmrow = new GroupManagerRow();

gmrow.Height = 24;

group.HeaderRows.Add( gmrow );

Xceed have GroupMangerRow for this purpose. You must add the GroupMangerRow to the header collection of the group object. And you can customize its Font, Fore Color, Title Format, Back Color, and other properties. Title format is very interesting. By default GroupMangerRow show the assigned groupby row column Title. But we can customize the Group by Header Row Title.

gmrow.TitleFormat = "%GROUPKEY% have %DATAROWCOUNT% Employees";

Here I have used only two keys to customize the Title format of the group header row. Please go to your Xceed Grid help and look for GroupManagerRow.TitleFormat property and look for more interesting feature to customized the group header row title.  

Sunday, November 26, 2006 Tree view control, very useful But. 2.0 ships with a whole new set of controls. Navigation controls are one of them. In navigation control we have three options

  1. Sitemap path
  2. Menu
  3. Tree View



Recently I have worked in a project which is a demo project where I had the pleasure of using the 2.0 tree view control. Below I will be demonstrating a simple way to use the treeview and some things that we should know while we use tree view control of 2.0 in our projects.


Obviously tree view control has node property and nodes can be create dynamically and modify the node collection on runtime. But it’s for only level one node. For level two nodes node is created just the way it is, but need to add in the child node property. So in a sense tree view has node property and nodes have no recursive node property and to deal with child node, node has child node collection.


Constructor of Node class has several overloads. Actually 5 of them are there.


TreeNode tn = new TreeNode("Text");

TreeNode tn = new TreeNode("Text", _value);


Here we should always be careful about the value property. This value property must be distinct for each collection.


For example if we have a Tree Node consists of three Nodes and each and every done has value property as a same value. SelectedNodeChanged even returns always the first node of the collection.


TreeNode tn1 = new TreeNode("Node One",-1);

TreeNode tn2 = new TreeNode("Node Two",-1);

TreeNode tn3 = new TreeNode("Node Three",-1);





In the web application if we select node three that is tn3 … in SelectedNodeChanged event we will have th1 as SelectedNode. I don’t know how this happened but surely it happened. But if we provide different value in the value field of the node constructor this was okay. Even if we don’t provide any value things work just fine.


Tree view has a wide range of configuration and style settings. Among these StaticItemStyle and StaticItemHoverStyle is most useful.


Well sometime we need to disable a node in our view. But TreeNode class do not have any enable or disable property, rather it has selection Action Property. We need to set the selection property value to none to make a node disabled.

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


Tuesday, September 12, 2006

Try.Catch. is not a good Practice

I don’t know using try catch in your code is good or bad. But I am sure that it makes your code run more slowly. For the early edge of my programming carrier I believed that c# language has managed the try catch or exception handling quite well. So we can use try catch as much as we can in our code to deal with the exception. But while working on the International Tax Expert project I found try catch is making my program working slow... this happens specially in paring a string to integer.

Let say

We have a code portion like

bool IsValidInteger(string s)
int x = int.parse(s);
return true;
return false;

If we manage to provide an invalid string which is not an integer the program returns the accurate value that is false. And for only one case this works fine and no performance degradation occurs.

But if we have to fill a data grid which has 1000 rows and one columns value is filed using the above mentioned function to show an icon or assign formatting for the data to show on the cell. The performance hit shows, and the program run slow.

So it is better to avoid “try catch” as much as you can in your code, there is always a good way to code such things. We should always remember coding is also an art and we can make it stylish.

Our senior software Engineer Hasan Shahriar Masud provided a good example on this matter the example is given bellow.

“We should not use try-catch if we can logically conclude the exception. It will help the performance, which munna(that is me) proved.

For example

//We should not write
//Do Something 1
//Do Something 2
//We should write
If (B==0)
Do Something 2
//Do Something 1

I have investigated this on Xceed grid 3.1 in case of data convertion. May be its a problem of xceed grid.

Xceed Grid 3.1 very cool data grid component

Recently in our project we have started to use xceed grid 3.1. Well xceed is very smart to introduced few new features.
Two most interesting features that impressed me is xceed grid report features. and its fixed column feature. this two feature is badly needed in our project . thanks to xceed that the reporting now easy like ice-cream.
let me give you an example how easy its is to create a report from a grid.

using( GenerateReportForm generateReportForm = new GenerateReportForm( this.gridControl1 ) ) 
enerateReportForm.ShowDialog( this );

Very easy . and the fixed column feature is more easy all you have to do is to set a property of the column. that the property is "isFixed"

Thursday, August 31, 2006

Windows presentation foundation.. visited

Recently we developed a spacer project. Goals for this project is to learn new technologies of Microsoft. Microsoft is developing the new generation of windows programming and web programming environment. As part of this evolution, Microsoft developing four major technology

1. Windows presentation foundation.
2. Windows Communication foundation.
3. Windows Work Flow Foundation
4. Windows Card Space

In our project we covered two technology that is WCF ( Communication Foundation ) and WPF (Presentation foundation). And we used recently released customer preview that is JULY CTP. In my point of view windows presentation foundation is a Break through in windows programming environment. Same interface is serving the UI for both web and windows. Pretty good. Event thought the performance is a good and big issue. I hope Microsoft is going to cover the lacks that WFP has in its Release product.

WCF ( Communication foundation ) this "the" future web service or inter-process communication service. or we can call the service of taking to every one. very well organized and well designed that can be used in local machine as windows service and also in web service.

More of .net frame work discussion will be listed in my blog.

But Bottom result is that i like the idea of both WPF and WCF.