Hi All, I am Very New in Infragistics win Controls. How get the columns index same as display in Grid LayOut,
Even if some columns are hidden in between. Suppose i have 20 columns in Grid, and 5 to 15 columns visible false, so 16th columns position in Grid is 6. and i want to get 16th column index 6, How it is posible?
The best way to do this is to reference the column by Key. The Index of the column can change, but the Key will always be the same.
But what about if the rowLayoutStyle is set to GroupLayout, in that case that's not true.
In datagridview, if i want to display column 5 in position 1 i would do the following:
Datagrid[4].DisplayIndex = 0;
How do i do this with Infragistics control?
Thanks
Joe
Hi Joe,
It depends what RowLayoutStyle you are using. But most of the time, you would do something like this:
this.ultraGrid1.DisplayLayout.Bands[0].Columns["column key"].Header.VisiblePosition = 0;
Of course, if your grid is bound to a data source at design-time, you can just click and drag the column headers on the design surface and put them where you want them.
Did you read the post I linked to above? That post explains exactly, and in great detail, exactly why the code you have here does not work and also has sample code which explains how get it to work correctly.
Unfortunately, this is existing code that I don't have the option of changing. Even so, that doesn't explain the issue with columns not displaying correctly when changing the VisiblePosition property. :(
Change the order of columns in Ultragrid - NetAdvantage for Windows Forms - WinGrid
A much easier way would be to just use the Save and Load methods on the grid's DisplayLayout instead of writing this code yourself.
It seems setting VisiblePosition in version 12.2 of the control doesn't work. Here's what I'm doing:
foreach (var column in uGridAddressRanges.DisplayLayout.Bands[0].Columns) column.Hidden = true;
int count = 0;
foreach (ConfigEntry configEntry in userConfig) { Console.WriteLine(configEntry.Value.ToString() + codeTable.CodeTableEntries.Item(configEntry.Value).CodeName);
foreach (var column in uGridAddressRanges.DisplayLayout.Bands[0].Columns) { if (column.Header.Caption == codeTable.CodeTableEntries.Item(configEntry.Value).CodeName) { column.Header.VisiblePosition = count; column.Hidden = false;
count++;
break; } } }
The grid has about 25 columns, but I'm trying to allow the user to select and reorder columns they want to see and persist that between sessions. The first 6 columns are ordered correctly, but the remaining 6 get shuffled around with no logic behind them that I can see. Am I doing something wrong?
Thanks Mike !