We have two bands. Depending upon a condition in each row of Band(0), we want to either show/hide a column on its Band(1) child rows.
Instead of hiding the column, simply setting the header text for the column to String.Empty would also work (we don't have to worry about the cells since they'll be empty anyways).
Is there any way to achieve this effect? The typical ways I'd solve this problem unfortunately hide the column across the whole grid, which is not what we want.
Hi,
Is the column you want to hide the last column? You can hide the column using a CreationFilter or DrawFilter, but this would not remove the space - there would still be a gap where the column would have been. So if it's the last column, this would work better.
If not, then it's probably not a good approach to take, because the borders would look odd and you'd have a big gap in your grid.
If you just want to blank out the column header, then you could set the column.Header.Caption to a single space character so it appears blank.
Another option might be to restructure your data source so that there are two child bands which are siblings to each other - one with the column and one without it. Then you just make sure that each parent row only has child rows in one band or the other, but not both. The down side of this approach is that you have to change your data structure, and also that it would not be easy to switch the column on and off based on a value in the parent row.
Another option you might consider is using UltraWinTree instead of UltraWinGrid. The up side is that you can assign a ColumnSet to a nodes collection dynamically. So this would allow you to hide or remove the column under the parent node with no problem. The down side is that you would have to change your grid to a tree, and also that the tree lacks certain grid functionality that you might need like summaries, filtering, printing, and exporting.
Hello Mike,
I am working with Jeff on this issue.
There are two columns that we want to hide, but they are the two latest columns, so it seems like using the CreationFilter or DrawFilter would be the best option for this problem. Are there any existing posts in the forums that show how to set the specific subset of column headers that we're after to a specific value?
If not, how would we go about tackling this issue?
Thank you!
-Seth
Hi Seth,
If it's the last column (or two) then that will make things easier. I've given this some further thought, and I don't think you will be able to completely hide the column even with a CreationFilter, because the row borders will still extend to where the column would have been. But if you are not too picky about how it looks, I think you could achieve something acceptable.
I have attached a simple sample here that hides the cells by setting the Hidden property on the cell in the InitializeRow event and uses a CreationFilter to remove the header text.
That pretty much solved it.
In the CreationFilter, once we got down to finding the column we want where we do the following:
parent.ChildElements.Clear() Return True
We had do some some other extra stuff to do it only for the subset we want.
Dim subbandRow = TryCast(headerUIElement.Parent.GetContext(GetType(UltraGridRow)), UltraGridRow) Dim rowWithCondition = subbandRow.ParentRow
Then we grabbed the ListObject for the row with the condition and used that to decide if we want to hide the column header or not.
Thanks!
Let me know how it goes. If this is no good, there are other things you could try.
Thanks, Mike! We'll give it a look and see if we can use the creation filter like you did in your code, and if we like how it looks.