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

how to set GridControl column header

Hi,

I am using the sample code from "DropdownGrid_2008" to play around and trying to add headers to the drop down grid.

this is the code snippet:

this.GridB.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Office2007Blue;
this.GridB.Properties.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(239)), ((System.Byte)(255)));
this.GridB.Properties.GridLineColor = System.Drawing.Color.FromArgb(((System.Byte)(208)), ((System.Byte)(215)), ((System.Byte)(229)));
this.GridB.DefaultGridBorderStyle = GridBorderStyle.Solid;
this.GridB.ForeColor = System.Drawing.Color.MidnightBlue;
this.GridB.Font = new System.Drawing.Font("Verdana", 8.5F);
string[] header = new string[6];
header[0] = "Stephen";
header[1] = "Kenneth";
header[2] = "Nancy";
header[3] = "Ivy";
header[4] = "Clara";
header[5] = "Paddy";
this.GridB.Model.PopulateHeaders(GridRangeInfo.Cells(0, 1, 0, 6), header);


I thought it is pretty simple but this does not work. Can you tell me what's wrong?

thanks

3 Replies

LS Lingaraj S Syncfusion Team July 21, 2009 09:44 AM UTC

Hi Stephen,

Thank you for your interest in Syncfusion product.

The PopulateHeader method used to populate the Header depends upon the DataSource.

Refer the example code below:

// BindingListDatsource
IList list = new List();
for (int i = 1; i <=100; i++)
{
list.Add(new Foo("Syncfusion","Syncfusion"));
}
foos = new BindingList(list);
GridB.RowCount = foos.Count;
GridB.ColCount = 2;
GridB.PopulateHeaders(GridRangeInfo.Cells(0, 1, 0, 2), foos);
GridB.PopulateValues(GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount), foos);

// DataTable DataSource
DataTable dt = GetTable();
GridB.RowCount = dt.Rows.Count;
GridB.ColCount = dt.Columns.Count+1;
GridB.PopulateHeaders(GridRangeInfo.Cells(0, 1, 0, dt.Columns.Count), dt);
GridB.PopulateValues(GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount), dt);


If you want to set the HeaderText in GridControl, then please try using Text porperty in GridStyleInfo to achieve this behavior.

Refer the code below:

GridB[0,1].Text="Header1"; // Set the Header text for First header cell
GridB[0,2].Text="Header2";


Please let me know if you have any queries.

Regards,
Lingaraj S.


IS Ildar Sadykov January 7, 2016 11:13 PM UTC

This works only up to 10 columns. After 10 columns there are no names.
How to fix that?

Attachment: syncfusion_grid_column_name_limit_10_11067010.zip


MA Mahendran Annamalai Syncfusion Team January 11, 2016 02:00 PM UTC

Hi Ildar,

Thanks for using Syncfusion products.


We were not able reproduce the reported issue. We have attached our simple work-around sample that working fine at our end. So, could you please revert back the attached sample to reproduce the issue or else provide the steps to reproduce this issue? That would help us to find the solution. Refer to the sample from the below location.


Sample:   GridControl_Demo

Please refer the Kb link below.


https://www.syncfusion.com/kb/4491/how-to-populate-a-database-in-gridcontrol


Please let us know if have any concern about this.



Regards,
Mahendran A.


Loader.
Live Chat Icon For mobile
Up arrow icon