We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Using stacked header with custom data table

Hi, normally I build a grid like this:
(dt = custom data table)

grid.dt.Columns.Add(new System.Data.DataColumn("Col1",typeof(string)));
grid.dt.Columns.Add(new System.Data.DataColumn("Col2",typeof(string)));

CustomDataRow dr;
dr = (CustomDataRow)gridCards.dt.NewRow();
dr[0] = "1";
dr[1] = "2";
grid.DataSource = gridCards.dt;

This works fine, but how do I use stacked column headers with this? If I do this it does nothing:

var stackedHeaderRow1 = new StackedHeaderRow();
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col1,Col2", HeaderText = "Column Set 1" });
grid.StackedHeaderRows.Add(stackedHeaderRow1);

Is it possible to make it work? I am not sure how I associate the stacked child columns with my data table.

8 Replies

MA Mohanram Anbukkarasu Syncfusion Team November 21, 2019 01:40 PM UTC

Hi Chris,  
  
Thanks for contacting Syncfusion support.   
  
We have prepared a simple sample with DataTable using the provided details to check the reported issue in stacked headers. Unfortunately, we are unable to reproduce the issue in our end. We are unclear with the terms custom data table and CustomDataRow specified in your update. Please provide more details about this. The sample we have used to test the reported issue is available in the following link for your reference.    
  
 
  
Please have a look at the sample and let us know if we have missed any customization that you have done in your sample or try to reproduce the reported issue in the above given sample. It will be helpful for us to find the exact cause for the issue and provide a prompt solution at the earliest.    
  
Regards,   
Mohanram A.   




PH Phunction November 21, 2019 04:35 PM UTC

Great, thanks.
Once I moved the stackedheader addition last it worked fine.
I was adding the stackedheader before adding the columns to the datatable and binding  it which it did not like.


PH Phunction November 21, 2019 06:14 PM UTC

Found a different issue?

I would like to add 2 sets of stacked columns with the same names, it is possible?
For example:

     Col Set 1                    Col Set 2
Val1   Val2  Val3          Val1 Val2 Val3

I tried over riding DrawCell but I don't see that being called for column headers, just row headers.




MA Mohanram Anbukkarasu Syncfusion Team November 22, 2019 01:46 PM UTC

Hi Phunction, 

Thanks for your update.  

We are unclear with your requirement that whether the Val1, Val2 and Val3 are the column headers (mapping names of the column) or stacked headers. It is not possible to add multiple columns to the DataGrid with same mapping name. Adding columns with same mapping name may lead to some issues. We suggest not to add like that and it is not possible to add those columns in two sets of stacked headers. If the Val 1, Val 2 and Val 3 are the stacked headers, then it is possible to add them in two sets of stacked columns as shown in the following code example. 

Code example :  

var stackedHeaderRow2 = new StackedHeaderRow(); 
stackedHeaderRow2.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col1,Col2,Col3", HeaderText = "Col Set 1" }); 
stackedHeaderRow2.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col4,Col5,Col6", HeaderText = "Col Set 2" }); 
dataGrid.StackedHeaderRows.Add(stackedHeaderRow2); 
 
var stackedHeaderRow1 = new StackedHeaderRow(); 
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col1", HeaderText = "Val1" }); 
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col2", HeaderText = "Val2" }); 
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col3", HeaderText = "Val3" }); 
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col4", HeaderText = "Val1" }); 
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col5", HeaderText = "Val2" }); 
stackedHeaderRow1.StackedColumns.Add(new StackedColumn() { ChildColumns = "Col6", HeaderText = "Val3" }); 
dataGrid.StackedHeaderRows.Add(stackedHeaderRow1); 


Please have a look at the above sample and please get back to us with more details if it doesn’t meet your requirement. 

Regards, 
Mohanram A. 



PH Phunction November 22, 2019 11:10 PM UTC

HI, this did not work for me. also, this is for Windows.Forms not WPF, not sure if that makes a difference.

Is it possible to intercept the drawing of the columns headers? Why does DrawCell for every other type of cell except column headers?
If I can do that it would be easy.

The option to directly set the header text of a column would be nice.


MA Mohanram Anbukkarasu Syncfusion Team November 25, 2019 01:07 PM UTC

Hi Phunction,   
  
Sorry for the inconvenience caused.    
  
The DrawCell event will never fire for the column headers as it includes rendering of filtering and sorting icons. However, you can set the header text for the column using the HeaderText property of the column as per your requirement as shown in the below code example.   
  
Code example:    
  
this.sfDataGrid1.Columns["Col1"].HeaderText = "Val1";   
  
  
    
  
Please refer the above sample and let us know if it doesn’t meet your requirement.    
  
Regards,   
Mohanram A  




PH Phunction November 25, 2019 05:35 PM UTC

OK, that was easy, I was sure I looked for that property but could not find it.

Thanks for the help.


FP Farjana Parveen Ayubb Syncfusion Team November 26, 2019 05:08 AM UTC

Hi Chris, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon