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.

Get Column Index of GridGroupingControl when GroupingBy a different Column

Thread ID:

Created:

Updated:

Platform:

Replies:

103015 Mar 22,2012 05:44 PM Apr 12,2016 04:57 AM Windows Forms 5
loading
Tags: GridControl
Eric Robishaw
Asked On March 22, 2012 05:44 PM

I need to find the column index of a column in a GridGroupingControl WHEN it is grouped by a column other than the one I'm looking for.

I need to find it DURING: Grid_TableControlCurrentCellValidating()


I.e., my datasource has 4 columns:
A,B,C,D

If the user has grouped by B

I need to find the index of "D" if I do not know whether it is "D" or "d" (case)

The following works IF and ONLY IF there is NO grouping:

int colIndex = FindColumnIndex(grid.TableDescriptor.VisibleColumns, "d")


private int FindColumnIndex (GridVisibleColumnDescriptorCollection visibleColumns, string columnName)
{
int index = 1; //one based column indexes
columnName = columnName.ToLower();
foreach (GridVisibleColumnDescriptor col in visibleColumns)
{
if (col.Name.ToLower() == columnName)
{
return index;
}
index++;
}
return -1;
}

HOWEVER, whenever a user has grouped columns, the above code returns the wrong index.

For example:

grid.Model[grid.CurrentCell.RowIndex, colIndex].CellValue

This returns the value for the Column BEFORE the one I need, WHEN a field is grouped.

I have tried using the TableDescriptor.Columns collection instead of the VisibleColumns collection, but it's no better.

HELP!





Asarudheen S [Syncfusion]
Replied On April 1, 2012 02:23 PM

Hi Eric,

Thank you for your interest in Syncfusion products.

We are unable to reproduce the reported issue from our side. As a suggestion please make use of following code to resolve the issue.

int index= this.gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf(columname);

Could you please send us simple sample to replicate your issue so that it will more helpful to update you the exact solution?

Regards,
Asarudheen.


Eric Robishaw
Replied On April 1, 2012 11:24 PM

VisibleColumns.IndexOf(columname) only works if you have the exact case of the columnname...

But for various reasons, I do not always know the exact case of the column name, it could be Dog, DOG, or dog...




Ragamathulla B [Syncfusion]
Replied On April 10, 2012 12:55 AM

Hi Eric,

Thanks for the update.

You can get 'Column Index' of GridGroupingControl by using the following code.

//way 1
this.gridGroupingControl1.TableDescriptor.FieldToColIndex(fildname);
//way2 this.gridGroupingControl1.TableDescriptor.ColIndexToField(colindex);


Let me know if you have any further concerns.

Regards,
Ragamathullah B.


QLT User
Replied On April 11, 2016 08:09 PM

does this actually work ?
this.gridGroupingControl1.TableDescriptor.FieldToColIndex(fildname);

i think it takes an int and not a string. i would like to get the index from the columnname

Piruthiviraj Malaimelraj [Syncfusion]
Replied On April 12, 2016 04:57 AM

Hi QLT user,

Thank you for your interest in Syncfusion products.

The column collection is maintained in the TableDescriptor.Columns and TableDescriptor.VisibleColumns. In order to get the column index from column name , you can make use of IndexOf method of VisibleColumns or Columns. Please make use of below code and refer to the sample.

Code snippet

int index = this.gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("ColumnName");

int id = this.gridGroupingControl1.TableDescriptor.Columns.IndexOf("ColumnName");



Sample

http://www.syncfusion.com/downloads/support/forum/103015/ze/DataGrid1575736822


Regards,

Piruthiviraj


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.

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.

;