how can we write formatted text in the caption of the ultragrid.
example: TOTAL AMOUNT: 123456 (the number is in bold while the letters are regular) ??
Hi Ahmed,
Oh, that's excellent, you are already 90% of the way there. All you need to do now is update the CreationFilter to do the same thing it's already doing for the grid caption and apply it to the GroupByRow. It's almost the same code. The only real difference is that in addition to checking for CaptionAreaUIElement, you will also need to check for GroupByRowDescriptionUIElement. And instead of hard-coding the xml string, you will just get the Description from the GroupByRow and use that.
I have attached an updated version of Mike's sample that does this. Here's the CreationFilter code for quick reference:
public class FormattedCaptionCreationFilter : IUIElementCreationFilter { public void AfterCreateChildElements(UIElement parent) { } public bool BeforeCreateChildElements(UIElement parent) { if (parent is CaptionAreaUIElement) { // Reuse the existing FormattedTextUIElement if there's already one there FormattedTextUIElement childElement = parent.ChildElements.OfType<FormattedTextUIElement>().FirstOrDefault(); if (childElement == null) { childElement = new FormattedTextUIElement(parent); parent.ChildElements.Add(childElement); } // In order to customize the formatted text that appears in the caption, modify this statement string formattedText = "<p align = \"center\">" + parent.Control.Text + "</p>"; childElement.Value = ParsedFormattedTextValue.Parse(formattedText, ParsedFormattedTextValue.ValueType.AutoDetect, out Exception ex); childElement.Rect = parent.RectInsideBorders; return true; } else if (parent is GroupByRowDescriptionUIElement) { // Reuse the existing FormattedTextUIElement if there's already one there FormattedTextUIElement childElement = parent.ChildElements.OfType<FormattedTextUIElement>().FirstOrDefault(); if (childElement == null) { childElement = new FormattedTextUIElement(parent); parent.ChildElements.Add(childElement); } var groupByRow = parent.GetContext(typeof(UltraGridGroupByRow)) as UltraGridGroupByRow; // In order to customize the formatted text that appears in the caption, modify this statement string formattedText = groupByRow.Description; childElement.Value = ParsedFormattedTextValue.Parse(formattedText, ParsedFormattedTextValue.ValueType.AutoDetect, out Exception ex); childElement.Rect = parent.RectInsideBorders; return true; } return false; } }
8473.UltraGridFormattedCaption.zip
my ultragrid consists of the following columns: product, component, quantity;
they are grouped by a fourth column called Header which is a string contains:
(counter. project reference | client name) -- (1. 8579.01 | apartment barcelona)
check the image below:
my goal is to give distinction to the various elements in the string of the groupbyrow.
1- first option: i need to make the project reference (8579.01) red or bold.
2- second option: i need to put the (counter and project reference on first line, then the client name (apartment barcelona) on the second line.
i tried simple ways like going to the intializeGroupByRow and try to cut the e.Row.Description to get the project name then add
string.Format("<span style='color:#373636;font-family: Segoe ui; font-size: 9pt;'>{0}</span>", SemeString);
but didn't work because there is no way to make the groupbyrow style as FormattedText.
how can i make this possible?
Yes, you should be able to use the same technique to show FormattedText in a GroupByRow. But it's hard for me to see what you want from just a snippet of text like you have here. Could you explain what "project" and "client" are here? Maybe you could post a screen shot of what your grid looks like now with the grouping? The basic approach would be pretty much the same, except you would look for a GroupByRowUIElement and I think it will already contain a TextUIElement that you would need to remove and replace with a FormattedTextUIElement. For maximum flexibility and easy of use, what I would do is build the xml you want and set the Description property of the GroupByRow inside of the InitializeGroupByRow event. That way your CreationFilter just pulls out the Description string and assigns it to the FormattedTextUIElement.
is it possible to do the same for a groupbyrow?
how can i format the groupbyrow description to make it look like: 1. project | client ?
Excellent, that worked.
my code looked like the following:
private void FrmMain_Load(object sender, EventArgs e) {ultraGrid1.CreationFilter = new FormattedCaptionCreationFilter(); }
public class FormattedCaptionCreationFilter : IUIElementCreationFilter { public void AfterCreateChildElements(UIElement parent) { }
public bool BeforeCreateChildElements(UIElement parent) { if (parent is CaptionAreaUIElement) { // Reuse the existing FormattedTextUIElement if there's already one there FormattedTextUIElement childElement = parent.ChildElements.OfType<FormattedTextUIElement>().FirstOrDefault();
if (childElement == null) { childElement = new FormattedTextUIElement(parent); parent.ChildElements.Add(childElement); }
// In order to customize the formatted text that appears in the caption, modify this statement //string formattedText = "<p align = \"center\">" + (parent.Control as UltraGrid).Text + "</p>"; string formattedText = "TOTAL AMOUNT: " + "<span style = 'font-weight: bold;'>" + (parent.Control as UltraGrid).Text + "</span>";
Exception ex = new Exception(); childElement.Value = ParsedFormattedTextValue.Parse(formattedText, ParsedFormattedTextValue.ValueType.AutoDetect, out ex); childElement.Rect = parent.RectInsideBorders; return true; } return false; } }