Friday, July 6, 2007

Multi header implementation in UltraWebGrid

Multi-Header Implementation is possible in Infragistic's UltraWeGrid.



So how to do it:
  1. Mostly if we are going for Multi column header then there should be some static Columns
  2. So first write the code to Bind the DataSet
  3. Use Initialize Layout Event to write the Static Columns and also to work on the Spanning of the columns.

Sample Code


public void UltraWebGrid1_InitializeLayout(object sender,
Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e)
{
// Create Static UltraGrid Header
Infragistics.WebUI.UltraWebGrid.ColumnHeader ch = new
ColumnHeader(true);
// other Code
// .......
// Initilaize the Spans here
ch.RowLayoutColumnInfo.OriginY = 0;
ch.RowLayoutColumnInfo.OriginX = 0;
ch.RowLayoutColumnInfo.SpanX = 2;
ch.RowLayoutColumnInfo.SpanY = 1;
// other Codes
}



The Methods Span X, OriginX are self explanatory, but what is important is to visualize how the axis is getting created in UltraWebGrid. This is shown in the dig above.
One more thing to note is correct calculation of the Spans and Origins of each header is critical.
If you get it wrong then
  1. The Headers may be scrambled
  2. Some Headers may be lost

Note that no error Will be thrown on either of the case so write the Origin and Spanning of the columns carefully


The Story Behind
I was new to .net and Infragistics and one requirement came up to construct a Grid using Multi-Header. I know for sure that this will be possible using Infragistics but don't know how exactly to do it. I tried a lot of googling but in vain. Finally I got a Chinese web site which talked about this :)

That was a wake up call for me, I thought how many ppl would've searched for this implementation and would've suffered?

I decided then that I should write a Blog about this and other things which I know and assume many ppl do not know. May be a guy reading this implementation might think its silly to do it in the way i wrote and can come back with a better approach. Or may be I'm duplicating a thing which would've been already known to many ppl. If my consciousness says to share something then I will definitely share it.

4 comments:

Anonymous said...

Hello, I really appreciate your intention in putting up some tips on this for people like us. I'm new to Infragistics programming too.

Could you kindly explain a short scenario of merging two HEADER columns as well as two HEADER rows?

Thanks a ton!

Ramachandran said...

Hi Anonymous,
It's almost 9 months since I stopped using Infragistics, and I'm getting rusty....
Also I don't have the software right now.....
But I think the code should be something like this:
***********************************
ch.RowLayoutColumnInfo.OriginY = 0;
ch.RowLayoutColumnInfo.OriginX = 0;
ch.RowLayoutColumnInfo.SpanX = 2;
ch.RowLayoutColumnInfo.SpanY = 2;
***********************************
Do write back here on how you solved the issue so that others can use it.

$$ said...

I have done the same thing...but when i export to excel this row is not getting exported....I am using Infragistics 8.2

Ramachandran said...

Hi Smriti,
I used custom C# code for writing the content to excel. I no longer use Infragistics. Back in 2007 Infragistics dint have good functionality to export to excel for Multi-header Grid.