Hi. I have a grid that has a date column which can have slightly different meanings based on the group. I would like to dynamically change the caption based on which group it is in but I'm not having much luck. I am changing this in the InitializeGroupByRow event now but it changes the caption for the entire grid. Is this possible?
Here is the code that isn't working for me...
void gdApplicantCases_InitializeGroupByRow(object sender, InitializeGroupByRowEventArgs e){ if (e.Row.Value.Equals("IA")) e.Row.Band.Columns["AppDate"].Header.Caption = "Intake Date"; else if (e.Row.Value.Equals("AA")) e.Row.Band.Columns["AppDate"].Header.Caption = "Application Date";...}
Thanks Mike - that worked.
Hi,
Looks good.
Instead of looping through the child elements at the bottom, you could use the GetDescendant method. It's not any more efficient (it has to loop internally), but it would be less code and maybe a little easier to read.
Thanks Mike! This class worked for me:
private
class DataGridHeaderCreationFilter : IUIElementCreationFilter {
public bool BeforeCreateChildElements(UIElement parent) { return false; }
public void AfterCreateChildElements(UIElement parent) {
if (parent is HeaderUIElement) {
HeaderUIElement uiElement = (HeaderUIElement)parent;
Infragistics.Win.UltraWinGrid.
ColumnHeader uiColumnHeader = uiElement.GetContext(typeof)Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader;
if (uiColumnHeader == null || uiColumnHeader.Column.Key != "ApplicationDate")return;
UltraGridRow uiGridRow =uiElement.GetContext(typeof(UltraGridRow)) as UltraGridRow;
if (uiGridRow == null)return;
string applicationDateType;switch((string)uiGridRow.Cells["ApplicationType"].Value) {
case "IA":applicationDateType = "Intake Date";break;case "AA":applicationDateType = "Last Rec'd";break;default: applicationDateType = "App Date";break;
}
foreach (UIElement childElement in uiElement.ChildElements) {
if (childElement is TextUIElement){ ((TextUIElement)childElement).Text = applicationDateType; break;}
Thank you Mike. I appreciate your assistance and will give this a shot.
You can't do it this way - the Band here is a backward pointer to the Band that the row is in and they are all in the same band.
The only way to do something like this would be to use a DrawFilter or a CreationFilter to modify the text of the UIElements in the grid. I'd use a CreationFilter, myself. You could trap for the HeaderUIElement for the column, then use GetContext on it to get a RowsCollection or possibly a Row. Then from there you could get the parent row and examine it to determine what the header text should be. Then you have to find the TextUIElement inside the ChildElements collection of the HeaderUIElement and set it's Text.