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.
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.
It works !! Thanks!!
I have one more question. Suppose I have a column names A, and to get this column index i use the following function:
int index = Grid.DisplayLayout.Bands[0].Columns["A"].Header.VisiblePosition;
Let's suppose further that function returns an index of 11. If I now use
Grid.DisplayLayout.Bands[0].Columns[
"A"].Header.VisiblePosition = 6 to move this column to position 7(zero index).
If I now re-use, index = Grid.DisplayLayout.Bands[0].Columns["A"].Header.VisiblePosition;
Will this return an index of 6 or 11? Is there a way to get the current column index?
Thanks
Joe
Sorry I meant to say , if i now use the CellListSelect event and call e.Cell.Column.Index;
Will this return an index of 11 or 6? Currently i have an if statement to check if this column is selected.
if (e.Cell.Column.Index == Index)
// do something;
and if this e.Cell.Column.Index returns an index of 11, this if statement will never hit.
ThanksJoe
Yes, changing the VisiblePosition of a column may change the Index of that column. As a rule, you should not refer to a specific column by index, you should always use the key.
The Index may change, but the Key never will (unless you or your data source changes it).
Indices are great if you want to loop through all of the items in a collection and do something to all of them. But if you want one particular column, the key is a better choice.
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?
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.