I have a multi-band UltraGrid in my winforms project. In one of the child bands, there is a column which I dont want to always see. Whether or not I want to see it is dependant on a field in the parent row.
So now I'm setting the column hidden/visible in the BeforeRowExpanded event of the ultragrid, as below:
void ultraGrid_BeforeRowExpanded(object sender, CancelableRowEventArgs e)
{
Item item = e.Row.ListObject as Item;
if (item.SingleColour)
e.Row.ChildBands[constColourBand].Band.Columns["UnitCost"].Hidden = true;
e.Row.ChildBands[constColourBand].Band.Columns["UnitCost"].ExcludeFromColumnChooser = ExcludeFromColumnChooser.True;
}
else
e.Row.ChildBands[constColourBand].Band.Columns["UnitCost"].Hidden = false;
e.Row.ChildBands[constColourBand].Band.Columns["UnitCost"].ExcludeFromColumnChooser = ExcludeFromColumnChooser.False;
The problem is, this code changes the column hidden property for *all* bands - that is, the child bands (of this type) within other parent rows. Obviously this is not what I want - I only want to set this property for the child band being expanded, not the child bands for other rows.
How can I acheive what I want here? How do I prevent it from hiding the columns in the child bands of other rows?
Thanks.
Hi,
You cannot. A Column is either hidden or it's not. There's no way to hide it only in some islands of data and not in others.
You might consider using WinTree instead of WinGrid. The WinTree allows you to assign a ColumnSet to a collection of Nodes. Thus you could have two different ColumnSets that are the same except for the existance (or lack thereof) or a particular column and assign that ColumnSet to the nodes collections as you want.
Of course, the tree has other limitations. For example, it does not support Filtering or Summaries like the grid does.
As Mike mentioned, you either hide or show a column, but you can hide or show the cell!.
Inside the InitializeRow event of the grid write the following code:
if (!e.ReInitialize)
{ if (e.Row.HasParent() && e.Row.ParentRow.Cells.Exists("Your Condition Column Key Here")) { if (e.Row.ParentRow.Cells["Your Condition Column Key Here"].Value == hiddenValue) e.Row.Cells["Column to hide here"].Hidden = true; else e.Row.Cells["Column to hide here"].Hidden = false; }
hope that helped
Nassos
Fweee,
what i suggest is in the picture embedded, the cells in the red box the hidden property of thet cells is Hidden!!
It has nothing to do with column nor band!!!!
reyzidis said:As Mike mentioned, you either hide or show a column, but you can hide or show the cell!.
Thanks, but the real issue was what Mike said - I cant do this within the child band of one parent row, without it effecting the child bands of all rows. I'm now getting around this by only allowing the user to expand one row at a time (when they expand one, it contracts any others that are open).