Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day

How do I get the value of the header name in a datgridview without using indexes?

Thanks
Posted
Comments
Richard MacCutchan 13-Mar-12 8:13am    
Header of what?

Hi,

C#
foreach (DataGridViewColumn column in dataGridView.Columns)
   {
       //Maybe check if value matches
       if(column.HeaderText == "Column1")
       {
           //Do Something
       }
       
   }


Hope that helps.

Best Regards
 
Share this answer
 
SQL
if (dataGridview.CurrentRow.Cells["Comlumn header name"].Value.ToString() == "Cell in Datagridview")
{
//Do Something
}
 
Share this answer
 
v2

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