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

Getting the Column Name using ColToFieldIndex

Thread ID:

Created:

Updated:

Platform:

Replies:

21443 Nov 10,2004 02:43 PM UTC Nov 10,2004 08:00 PM UTC Windows Forms 4
loading
Tags: Grouping
Erlly Bayuelo
Asked On November 10, 2004 02:43 PM UTC

In our application grid,we have a "View" collection in which the user specifies which columns and in which order to show them on the grid. Therefore, we are only adding the columns of the underlying datasource that we want to view using the GridColumnDescriptor collection Add() method. As a result, our Fields collection and our Columns collection are not in the same order and do not have the same number of items. Now when we are in grid_TableControlPrepareViewStyleInfo() or grid_QueryCellStyleInfo() we are trying to get the name of the column of the current cell. We have been using: this.grid.TableDescriptor.Columns[this.grid.TableModel.ColIndexToField(e.Inner.ColIndex)].Name and e.TableCellIdentity.Table.TableDescriptor.Columns[grid.Table.TableModel.ColIndexToField(e.TableCellIdentity.ColIndex)].Name respectively. However, I want to make sure that I am doing this correctly since the ColIndexToField naming convention seems to imply that I have to use this to get items from the Fields collection and I am using it to get an item from the columns collection. It seems to be working at the moment and ironically when I use it against the fields collection it does not work properly [I think it is because my Fields collection does not match my Columns collection]

Administrator [Syncfusion]
Replied On November 10, 2004 03:56 PM UTC

Hi Erly, your method calls should be fine as long as you don''t have column sets and as long as you did not modifiy the VisibleColumns collection. Better is to use the information that is already provided to you through GridTableCellStyleInfoIdentity. Example: GridTableCellStyleInfo style = e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex]; GridTableCellStyleInfoIdentity id = style.TableCellIdentity; GridColumnDescriptor column = id.Column; Stefan

Erlly Bayuelo
Replied On November 10, 2004 05:01 PM UTC

Hi Stefan, Thanks for the info. The code that you sent me works fine for Record Element types but not for Caption Rows (i.e. id.Column is undefined) that is why I was using the code I originally listed which works for both. We have CaptionSummaryRows and sometimes we want to get column names when we transverse those too. I have now since modified my code to use your code for RecordFieldCell and AlternateRecordFieldCell. However I have left my code whenever TableCellIdentity.DisplayElement is CaptionRow. So, to answer my original question does ColToFieldIndex() return the index of the Fields collection or the Columns collection? In my code I am using it to successfully to query the columns collection.

Administrator [Syncfusion]
Replied On November 10, 2004 07:57 PM UTC

Hi Erlly, it is correct only if you have not modified the VisibleColumns collection. Better is the TableDescriptor.GetHeaderColumnDescriptorAt instead. Then you are on the safe side. Its implementation looks as follows public GridColumnDescriptor GetHeaderColumnDescriptorAt(int colIndex) { GridColumnDescriptor[,] recordRowColumns = TableDescriptor.RecordRowColumns; int fieldNum = TableDescriptor.ColIndexToField(colIndex); return recordRowColumns[0, fieldNum]; } Use it this way: GridColumnDescriptor column = e.TableCellIdentity.Table.TableDescriptor.GetHeaderColumnDescriptorAt(e.TableCellIdentity.ColIndex) Stefan

Administrator [Syncfusion]
Replied On November 10, 2004 08:00 PM UTC

Correction: GridTable table = style.TableCellIdentity.Table; GridColumnDescriptor column = table.GetHeaderColumnDescriptorAt(style.TableCellIdentity.ColIndex); It is a member of GridTable. Stefan

CONFIRMATION

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.

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

;