How do I get a column of a data grid view by the header text rather than by the index or name property?
What I tried so far is the my intuitive approach:
// Identifiers used are:
string myHeaderText = "Header Text";
dataGridViewColumn = dataGridView.Columns[myHeaderText];
however this returns
Object reference not set to an instance of an object.
It is returning
because
is looking for a column in the the dataGridView with a Name Property = myHeaderText not HeaderText property. To get around this you could try the following:
this creates an extension method to DataGridView