I have a DataGridView with some columns in it. For example I have the column colService and my DatagridView is called dgvServices. Then the following values are different.
colService.Index
dgvServices.Columns[colService.Name].Index
I also checked their DisplayIndex property and it is also different. In my datagridview I have some hidden columns. Also some columns are bound to a datatable column and others not. Why are these 2 values different?
Thanks
It turns out that the problem occurred because AutoGenerateColumns property of the DGV is set to true. That way when the datasource is assigned to DGV new columns are created add override the existing ones. Setting AutoGenerateColumns to false solves the problem.