Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to name the columns of a datagrid in such a way as to be able to
refer to them by name? I'm aware of the dgTemp.Columns(8) concept; however, if I'm
referring to Column(8) and at a later date, I insert a column in the datagrid before that
column, I have to know and adjust all of the index references in the code behind.

Or is there a function which returns the column index based on the HeaderText of the column?

Thanks,
Steve
Posted

1 solution

You could always write a small converter utility that takes in a datagrid object and a requested header text returning the appropriate column index.
C#
private int GetColumnIndexByHeaderText( DataGrid dgObj, string headerText )
{
   // Loop through the columns and when you find the appropriate header text return the index.
}
 
Share this answer
 
Comments
Hiren solanki 24-Jan-11 22:26pm    
Message from OP:Thought so. Already wrote the loop. Just wondering if there was something more automated. Thanks for the quick jump in.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900