New to Telerik UI for WinFormsStart a free 30-day trial

Creating Custom Blocks

Updated over 6 months ago

RadAutoCompleteBox allows not only appearance customization via the formatting event, but also replacement of the default UI block representation. The CreateTextBlock event exposes this possibility.

You should create a custom text block that inherits from ITextBlock and any inheritor of RadElement. Let’s extend the default TokenizedTextBlockElement by adding a check box. You don’t need to implement the ITextBlock interface, because it is already defined in the base class:

C#
public class MyTokenizedTextBlockElement : TokenizedTextBlockElement
{
    private RadCheckBoxElement checkBox;
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(TokenizedTextBlockElement);
        }
    }
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        int index = this.Children.IndexOf(this.RemoveButton);
        this.checkBox = new RadCheckBoxElement();
        this.checkBox.StretchVertically = true;
        this.checkBox.StretchHorizontally = false;
        this.Children.Insert(index, this.checkBox);
    }
}

Then you should replace the default text block in the CreateTextBlock event handler, in the following manner:

C#
private void radAutoCompleteBox1_CreateTextBlock(object sender, CreateTextBlockEventArgs e)
{
    if (e.TextBlock is TokenizedTextBlockElement)
    {
        e.TextBlock = new MyTokenizedTextBlockElement();
    }
}

Finally, the text property should be set:

The subscription to the event, should be introduced before setting the text of the control.

C#
radAutoCompleteBox1.CreateTextBlock+=new CreateTextBlockEventHandler(radAutoCompleteBox1_CreateTextBlock);
this.radAutoCompleteBox1.Text = "Euro;USD;GBP;";

The following image demonstrates the final result:

WinForms RadAutoCompleteBox Creating Custom Blocks

See Also

In this article
See Also
Not finding the help you need?
Contact Support