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

Grid Column Header

Hi,

Could you let me know how to obtain the list of column names (headers) fron a grid (not the underlying data).

I tried something like this:

for (int i = 0; i < mainGrid.Model.ColumnCount; i++)
{
string name = GridRangeInfo.GetAlphaLabel(i);
}

However, I obtain the name = "A" , name = "B", name = "C", etc... instead of the real column names, e.g. name = "ID", name = "Name", name = "Address"

Could you advise please?

Thank you

Fred



1 Reply

RA Rajasekar Syncfusion Team April 23, 2012 07:16 AM UTC

HI Fred,

Thanks for your update. You can achieve this requirement by using the below code snippet,

///Way #1
List _columnHeaders = new List();
foreach (GridDataVisibleColumn vc in this.dataGrid.VisibleColumns)
{
if (vc.HeaderText == null || vc.HeaderText == "")
{
_columnHeaders.Add(vc.MappingName);
}
else
{
_columnHeaders.Add(vc.HeaderText);
}
}

///Way #2
List _columnHeaders1 = new List();
int tempIndex = 0;
if (this.dataGrid.ShowRowHeader)
{
tempIndex = tempIndex + 1;
}

if (this.dataGrid.GroupedColumns.Count > 0)
{
tempIndex = tempIndex + this.dataGrid.GroupedColumns.Count;
}

for (int col = tempIndex; col < this.dataGrid.Model.ColumnCount; col++)
{
_columnHeaders1.Add(this.dataGrid.Model[0, col].CellValue.ToString());
}

For your reference, please find the sample in the below location,

Sample: SyncfusionGDC.zip

Note: We have found that, the similar queries is posted in the Incident #93556. We have also updated the details in that Incident too. If you have any queries we request you to update in that Incident Itself for better follow up.

Please let us know if you have any queries.

Thanks,
Rajasekar




Loader.
Live Chat Icon For mobile
Up arrow icon