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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

3697 Apr 2,2003 09:44 AM Apr 2,2003 10:41 AM Windows Forms 2
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On April 2, 2003 09:44 AM

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 10:20 AM

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 10:41 AM

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;

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.

;