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 Ahmad,
I've put together a small sample that demonstrates how you might do this using a Creation Filter. The relevant code looks like this:
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>"; childElement.Value = ParsedFormattedTextValue.Parse(formattedText, ParsedFormattedTextValue.ValueType.AutoDetect, out Exception ex); childElement.Rect = parent.RectInsideBorders; return true; } return false; }
In this sample, I'm using the formatted text to center the caption, which reproduces the effect of the original implementation. You should modify the format as per your application's needs. You can find more information about Formatting Text and what types of formatting is supported in our help.
I've attached the full sample in case you would like to see it running.
UltraGridFormattedCaption.zip
Please let me know if you have any further questions.
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; } }