I have a datagrid having few columns-
The header of the grid is hyperlink and I am setting its value at runtime as follows-
string strQ1 = "<a href='somePage.aspx?ID=1'>gfgytyty<a>";
dtGrid.Columns[0].Header = strq1;
string strQ2 = "<a href='somePage.aspx?ID=2'>yhtryrtuyu<a>";
dtGrid.Columns[1].Header = strq2;
and so on...
It is working properly. Now suppose I want to get index of a perticular column of datatgrid by its name but I am not able to get it. I tried
int colIndex = dtGrid.Columns.IndexOf(dtGrid.Columns[strQ2]);
this should return 1 as columnIndex but it is returning -1,
Also, dtGrid.Columns[strQ2] giving me the null value.
what I am doing wrong here?
Columns
property. But aDataGridViewColumn
has noHeader
but aHeaderText
property. Maybe you mean wpfDataGrid
which columns have aHeader
property. Please don't mix up all together. – LavationDataGridViewColumnCollection.Item
-indexer property uses the name of the column not the header-text. – Lavation