I'm using the UltraGrid to show two levels of data. The first is the "master" grid, which is just a basic grid. The second is the sub data, which is displayed when you expand each row by clicking on the litle cross (in a second band).
The contents of the sub data band is not consistant. It can be loaded differently for each row of the master grid, showing very different data for each row. In order to let the user know what is in the sub data band, I hope to be able to change the caption of the band header for each row (of the primary data). So they expand one row, they might see the caption "Customers", they expand another row and it might say "Suppliers".
Is this possible? IF so, how. I cant see anything int the ChildBands property to allow me to do this.
Thanks.
Very handy thanks: Here is something similar translated into VB for those who use it. The main difference is I set the column header to blank in certain circumstances and am not checking that it has a parent row as instead I check for the presence of a particular column
Public Sub AfterCreateChildElements(ByVal uiElement As Infragistics.Win.UIElement) Implements Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements
'Are we on a UI element?
If uiElement Is Nothing Then
Exit Sub
End If
'Is the UI element a text element so we can change the text?
If Not uiElement.GetType().Equals(GetType(TextUIElement)) Then
'Grab the band header element.
Dim HeaderUI As HeaderUIElement
HeaderUI = uiElement.GetAncestor(GetType(HeaderUIElement))
If HeaderUI Is Nothing Then
' find the row associated.
Dim row As UltraGridRow = CType(uiElement.GetContext(GetType(UltraGridRow)), UltraGridRow)
' just to be safe
If row Is Nothing Then
'Do the necessary formatting so the bottom child group does not show any column header text, as the data will always be not editable and blank.
If row.Cells.Exists("CategoryId") = True Then
If row.GetCellValue("CategoryId") = 5 Then
If CType(HeaderUI, HeaderUIElement).Header.Column.Key = "Actual" Or CType(HeaderUI, HeaderUIElement).Header.Column.Key = "ActualNext" Then
CType(uiElement, TextUIElement).Text = ""
End Sub
Thanks a lot Mike. Thats perfect.
Hi,
Nah, the version is not relevant. It's my fault, I didn't even notice that. The BandHeadersUIElement contains all of the headers - band and column.
Anyway, here's the right way to do it:
void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { TextUIElement textElement = parent as TextUIElement; if (null == textElement) return; HeaderUIElement headerUIElement = textElement.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement; if (null == headerUIElement) return; if (false == (headerUIElement.Header is BandHeader)) return; UltraGridRow row = headerUIElement.GetContext(typeof(UltraGridRow)) as UltraGridRow; if (null == row) return; UltraGridRow parentRow = row.ParentRow; if (null == parentRow) return; // If we get here, it means that we are creating a text element for a band header // in a child band. So set the text of the element based on the parent row. textElement.Text = parentRow.Cells["Column 1"].Text; }
Thanks Mike. Thats very close to what I want.
When I run it though, it also changes the headers of the columns. Which seems odd, seeing as though it seems to be checking that it is the BandHeadersUIElement before going any further.
I had to downgrade the project to v12.1. That wouldnt effect that would it?
As CreationFilters go, this is a pretty simple one. So I whipped up a quick sample project that changes the caption of the band header on the child band based on a value in the parent row.