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.
Hi,
The UltraWinGrid does not support heterogenous data sources. In other words, all of the columns in the band have to be the same. So the only way to get a different set of columns to show up under different parent rows in the same band would be to have multiple child bands and this will likely cause a serious performance issue - depending on how many bands you are using.
Anyway, it's not entirely clear to me exactly what your requirements are. If you don't need different columns under each parent row and you just want the change the band header text based on the parent row, then there's no property for that, but you could achieve is using a CreationFilter to change the text of the TextUIElement in the header.
Mike Saltzman"] If you don't need different columns under each parent row and you just want the change the band header text based on the parent row, then there's no property for that, but you could achieve is using a CreationFilter to change the text of the TextUIElement in the header.
Yes - this is it. The actual columns are the same, I just want a different header.
The only article I can see on this refers to UltraWinTree, UltraWinToolbars and UltraWinExplorerBar. I guess I'll see if I can make it work here.
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=5510
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.
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?
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 a lot Mike. Thats perfect.
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