954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

get column name of currentcell in a radgridview

hi! how can i get the column name of the current cell in the radgridview?
RadGridView1 is the name of my datagrid.
these doesn't work:

RadGridView1.CurrentCell.Column.ToString();
RadGridView1.CurrentCellInfo.Column.ToString();
RadGridView1.CurrentColumn.ToString();


help me please...

loraine96
Newbie Poster
8 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

Try something like this:

string str = dataGridView1.Columns[0].HeaderText;
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Hi, to add to ddanbe`s post.
You can do it this way too:

foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                { 
                 //CELL here does not have a property of HeaderText.
                    //so you can do it like ddanbe showed or:
                    string header = dataGridView1.Columns[cell.ColumnIndex].HeaderText;
                }
            }
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

thanks for your suggestion. but it doesn't work. here's the error:

Telerik.Windows.Controls.GridViewColumn does not contain a definition for HeaderText

loraine96
Newbie Poster
8 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

Have you already checked this link and this link

abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: