DataGridView column DisplayIndex problem

  • Thread starter Thread starter Aleksey Timonin
  • Start date Start date
A

Aleksey Timonin

Hi guys,
I try to adjust columns order in DataGridView via DisplayIndex property and
it doesn't work me properly. Here is the code:

protected override void AdjustGridColumns() {
foreach (DataGridViewColumn clmn in _grdCustomizations.Columns)
clmn.Visible = false;
AdjustColumn("name", "View Customization");
AdjustColumn("userID", "User ID");
AdjustColumn("machineID", "Machine ID");
AdjustColumn("resolutionID", "Resolution ID");
AdjustColumn("createdOn", "Created On");
AdjustColumn("modifiedOn", "Modified On");
}

private void AdjustColumn(string name, string displayName){
DataGridViewColumn clmn = _grdCustomizations.Columns[name];
clmn.HeaderText = displayName;
clmn.Visible = true;
clmn.DisplayIndex = _grdCustomizations.Columns.Count - 1;
}


After I call AdjustGridColumns method it shows me the next columns order :

ID (that shoudn't be at all)
View Customization
Created On
Modified On
User ID
Machine ID
Resolution ID

So, what don't I right? Why the "ID" still visible? Why order of columns
doesn't right?

Thanks a lot
 
Hi guys,
I try to adjust columns order in DataGridView via DisplayIndex property and
it doesn't work me properly. Here is the code:

protected override void AdjustGridColumns() {
foreach (DataGridViewColumn clmn in _grdCustomizations.Columns)
clmn.Visible = false;
AdjustColumn("name", "View Customization");
AdjustColumn("userID", "User ID");
AdjustColumn("machineID", "Machine ID");
AdjustColumn("resolutionID", "Resolution ID");
AdjustColumn("createdOn", "Created On");
AdjustColumn("modifiedOn", "Modified On");
}

private void AdjustColumn(string name, string displayName){
DataGridViewColumn clmn = _grdCustomizations.Columns[name];
clmn.HeaderText = displayName;
clmn.Visible = true;
clmn.DisplayIndex = _grdCustomizations.Columns.Count - 1;
}


After I call AdjustGridColumns method it shows me the next columns order :

ID (that shoudn't be at all)
View Customization
Created On
Modified On
User ID
Machine ID
Resolution ID

So, what don't I right? Why the "ID" still visible? Why order of columns
doesn't right?

Thanks a lot

It looks to me like you set DisplayIndex for the 6 columns that you
call AdjustColumn for to the same value.
 
Back
Top