Iterating through Datagridview column headers
11,850
Solution 1
foreach (DataGridViewColumn column in myDataGridView.Columns)
{
DataGridViewColumnHeaderCell headerCell = column.HeaderCell;
string headerCaptionText = column.HeaderText;
string columnName = column.Name; // Used as a key to myDataGridView.Columns['key_name'];
}
Solution 2
You can iterate over the DataGridView.Columns
property retrieving its header via the Name
property as in this example. Now, if you have set an associated header cell then you need to use the HeaderText property instead.
Author by
TtT23
Updated on June 23, 2022Comments
-
TtT23 almost 2 years
Given a DataGridView, I'd like to iterate through datagridivew column headers.
How can this be done?