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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridDataBoundGrid Column Headers

Thread ID:





6349 Aug 9,2003 02:11 PM UTC Aug 10,2003 08:15 PM UTC WinForms 2
Tags: GridControl
Jeffrey Block
Asked On August 9, 2003 02:11 PM UTC

When I attach to a DataTable, I am expecting the column header to reflect the DataColumn.Caption property. It seems that this should be okay, but the grid seems to be displaying the DataColumn.ColumnName (which, per the docs is what is returned if the Caption property is not explicitly set) rather than the value of the Caption property. Am I missing something or is this designed behavior? I just checked the MS DataGrid and it ignores the property too...just _seemed_ like this is what that property of the DataColumn should be used for... I can get the value to work okay with the GridBoundColumn.HeaderText property, but wanted to keep this type of business logic (IMHO) seperated from the UI if possible and only have to have it at the source of the information. Thanks in advance for any responses... Jeff Block

Administrator [Syncfusion]
Replied On August 9, 2003 08:52 PM UTC

The databinding supports any IList or IListSource object. The only information for such general data source is the PropertyDescriptor. So, the HeaderText is initialized with the PropertyDescriptor.Name property. This is why things work as they do in a GridDataBoundGrid and in a DataGrid. That said, it would be possible to add checks for particular datasources to make use of additional properties that might be available. But just changing this functionality at this point would break the behavior of existing code. So, any changes would have to be implemented on a conditional basis. As a workaround, you could add the method below to your form and just call it after you set the datasource to the grid. This would allow you to control the headers just by setting the column captions.
public void SetCaptionIntoHeaderText(DataTable dt, GridDataBoundGrid grid)
	GridBoundColumnsCollection gbcc = grid.GridBoundColumns;
	if(gbcc.Count == 0)
		gbcc = grid.Binder.InternalColumns;
	if(gbcc.Count > 0)
		foreach(GridBoundColumn gbc in gbcc)
			DataColumn dc = dt.Columns[gbc.MappingName];
			if(dc.Caption.Length > 0 && !dc.Caption.Equals(gbc.HeaderText))
				gbc.HeaderText = dc.Caption;

Jeffrey Block
Replied On August 10, 2003 08:15 PM UTC

Thanks Clay, I figured as much, but it never hurts to ask! ;>) Thanks for the snippet too. I modified a bit to set a flag to see if the refresh was required, e.g. were any column headers actually changed.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon