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

How do I get the column number when the columns are reordered

Thread ID:





3697 Apr 2,2003 02:44 PM UTC Apr 2,2003 03:41 PM UTC WinForms 2
Tags: GridControl
Administrator [Syncfusion]
Asked On April 2, 2003 02:44 PM UTC

Hi, I have a databound grid. Its datasource is a DataTable. It contains 4 columns ID, Comment, Date and Priority. Say, I clicked on Comment cell on first row. I used: int col = grid.Binder.ColIndexToField(grid.CurrentCell.ColIndex), it returned 2. dataTable.Columns[col].ColumnName returns "Comment". It is good so far. Now I moved Comment field to the end (4). The above code returns col 4 and the column name is "Priority". I am interested in getting my DataColumn from DataTable for my current cell after reordering. How do I get that? Also, how do I get the current row after sorting the column (double clicking on a col header)? thanks, - Reddy

Curtis Koppang
Replied On April 2, 2003 03:20 PM UTC

I think I have seen the answer to both of your questions in previous postings, you may poke around a little to find them.

Administrator [Syncfusion]
Replied On April 2, 2003 03:41 PM UTC

The simplest thing to do is to get the field from the the column index, an dthen use teh field in teh GridBoundColumns (or Binder.InternalColumns) to get the assocuiated MappingName which should be the columnname.
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
int field = this.gridDataBoundGrid1.Binder.ColIndexToField(cc.ColIndex);
string mappingName = this.gridDataBoundGrid1.Binder.InternalColumns[field].MappingName;
Once you have teh columnname, you can use that to index the columns in your DataTable. One way to get the current row in the DataTable is to use the CurrencyManager.Current property.
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember];
DataRowView drv = (DataRowView)cm.Current;
DataRow dr = drv.Row;


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