Hello,
I have set up a grid with several groups. The user is able to hide or show columns with a column chooser. My problem is when they decide to hide all columns in a group: the group header is still visible and I would like it to disappear.
Is there a property somewhere that tells the grid to hide a group (and especially the group header) when all its columns are hidden? Or do I have to do it manually?
Regards,
Damien
Hi Hristo and Mike,
I was almost sure I would have to do it myself, but I preferred to check first. Sometimes you develop a big functionality... just to realise you have set a boolean to True or False somewhere to have the same behaviour...
I don't use RowLayouts, but I managed to adapt the code Hristo gave easily and all work well. I just would have guessed to use that particular event (AfterColPosChanged). But all is fine now, thank you.
PS: Mike, no worries! I have seen a lot of people using group "instead" of group-by, so it is quite understandable to get confused sometimes! ;-)
Hi Damien,
Sorry, when you wrote 'group' thought you meant OutlookGroupBy, not column groups.
To answer your question, no, there's no automatic way to do this built into the grid. But Hristo's code looks like it should work.
Hello Damien,
All that is need to do is to hide the group when you hide all column is to use the Hidden property of the parent group of the columns. Here is some code snipped that I used to determine which group to hide:
private void ultraGrid1_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e)
{
if (e.PosChanged == PosChanged.HiddenStateChanged)
UltraGridColumn ch = e.ColumnHeaders[0].Column;
if (ch.Hidden == true)
UltraGridGroup group = ch.RowLayoutColumnInfo.ParentGroup;
bool allIsHide = true;
foreach (UltraGridColumn col in group.Columns)
if (!col.Hidden)
allIsHide = false;
break;
}
if (allIsHide)
group.Hidden = true;
else
if (ch.RowLayoutColumnInfo.ParentGroup != null)
ch.RowLayoutColumnInfo.ParentGroup.Hidden = false;
This code will work if the group didn’t has sub group. If they has you should modify the code. Also this is working in case you have RowLayouts. If you have just a groups (band.Groups.Add()…), you also can use the hidden property of the parent UltraGridGroup.
Let me know if you have any further questions.
Hi Mike,
Not that's not what I meant... I'll try to illustrate it with an example. In my grid, I have say 4 columns: A1, A2, B1 and B2. Columns A1 and A2 are in group A, B1 and B2 in B. I have this:
| A | B | | A1 | A2 | B1 | B2 |
For some reason, the user wants to hide B1 and B2. Currently, on my application, if the user does that, columns B1 and B2 (and their headers) disappear, but not the group header. I have this:
| A | B | | A1 | A2 |
What I want is the group header to disappear as well and have this:
| A | | A1 | A2 |
I hope this helps you to understand better what I mean...
I'm not sure I'm following you. If the user hides all of the columns, then no group would have any columns. So you would have to hide all of the rows in the grid.
If that's what you want, then no, there's no automatic way to do that, you would have to do it in code.