New to Telerik UI for WinForms? Start a free 30-day trial
Adding items programmatically
Updated over 6 months ago
RadButtonTextBox supports adding items at run time, which means that you can manually populate it with data. The following examples demonstrate how to add different button elements to the RadButtonTextBox's RightButtonItems and LeftButtonItems collections.
Figure 1: Adding button elements

Add button elements programmatically
C#
Dictionary<int, string> glyphs = new Dictionary<int, string>();
List<RadButtonElement> buttons = new List<RadButtonElement>();
glyphs.Add(0, ""); //yammer
glyphs.Add(1, ""); //twitter
glyphs.Add(2, ""); //pinterest
glyphs.Add(3, ""); //google
glyphs.Add(4, ""); //facebook
glyphs.Add(5, ""); //linkedin
glyphs.Add(6, "\ue817"); //Reddit
glyphs.Add(7, "\ue81d"); //Tumbler
glyphs.Add(8, "\ue813"); // MySpace
for (int i = 0; i < 9; i++)
{
RadButtonElement radButtonElement = new RadButtonElement();
radButtonElement.DisplayStyle = Telerik.WinControls.DisplayStyle.Text;
radButtonElement.TextElement.CustomFont = "TelerikWebUI";
radButtonElement.TextElement.CustomFontSize = 10;
radButtonElement.TextElement.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
radButtonElement.Text = glyphs[i];
buttons.Add(radButtonElement);
}
radButtonTextBox1.RightButtonItems.AddRange(buttons[0], buttons[1], buttons[3], buttons[4]);
radButtonTextBox1.LeftButtonItems.AddRange(buttons[5], buttons[6], buttons[7], buttons[8]);
radButtonTextBox1.AutoSize = false;
radButtonTextBox1.Text = "";
The following code snippet demonstrates how to add programmatically different types of elements in RadButtonTextBox:
Figure 2: Adding Different Elements

Add different elements programmatically
C#
private void AddDifferentItems()
{
this.radButtonTextBox1.Multiline = true;
RadButtonElement buttonElement = new RadButtonElement();
buttonElement.Text = "Button";
buttonElement.Click += buttonElement_Click;
this.radButtonTextBox1.LeftButtonItems.Add(buttonElement);
RadToggleButtonElement toggleButtonElement = new RadToggleButtonElement();
toggleButtonElement.Text = "ToggleButton";
toggleButtonElement.ToggleStateChanged += toggleButtonElement_ToggleStateChanged;
this.radButtonTextBox1.LeftButtonItems.Add(toggleButtonElement);
CommandBarSeparator separator = new CommandBarSeparator();
this.radButtonTextBox1.LeftButtonItems.Add(separator);
RadRepeatButtonElement repeatButtonElement = new RadRepeatButtonElement();
repeatButtonElement.Text = "RepeatButton";
repeatButtonElement.Click += repeatButtonElement_Click;
this.radButtonTextBox1.LeftButtonItems.Add(repeatButtonElement);
RadCheckBoxElement checkBoxElement = new RadCheckBoxElement();
checkBoxElement.Text = "CheckBox";
checkBoxElement.CheckStateChanged += checkBoxElement_CheckStateChanged;
this.radButtonTextBox1.RightButtonItems.Add(checkBoxElement);
}
private void checkBoxElement_CheckStateChanged(object sender, EventArgs e)
{
RadMessageBox.Show("RRadCheckBoxElement is toggled");
}
private void repeatButtonElement_Click(object sender, EventArgs e)
{
Console.WriteLine("RadRepeatButtonElement");
}
private void toggleButtonElement_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
RadMessageBox.Show("RadToggleButtonElement.ToggleState is changed to " + args.ToggleState.ToString());
}
private void buttonElement_Click(object sender, EventArgs e)
{
RadMessageBox.Show("RadButtonElement is clicked");
}
private void RadForm1_Load(object sender, EventArgs e)
{
AddDifferentItems();
}