This is a migrated thread and some comments may be shown as answers.

iterate in AutoCompleteBox with Checkbox

1 Answer 69 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 2
Daniel asked on 24 Feb 2015, 01:32 AM
     Hi, how can i iterate to the items in AutoCompleteBox with Checkbox? I would like to get the email with checked.  Thanks in advance.

im using this code in to add checkbox in AutoCompleteBox.


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.checkBox.Checked = true;
            this.Children.Insert(index, this.checkBox);
        }
    }  








1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Feb 2015, 01:49 PM
Hello Daniel,

Thank you for writing.

You can introduce a public property returning the RadCheckBoxElement. Afterwards, you can iterate the AutoCompleteBoxViewElement.Children collection and find the checked TokenizedTextBlockElements:
public Form1()
{
    InitializeComponent();
 
    this.radAutoCompleteBox1.CreateTextBlock += radAutoCompleteBox1_CreateTextBlock;
    this.radAutoCompleteBox1.AutoCompleteDataSource = this.customersBindingSource;
    this.radAutoCompleteBox1.AutoCompleteDisplayMember = "ContactName";
    this.radAutoCompleteBox1.AutoCompleteValueMember = "CustomerID";
}
 
private void radAutoCompleteBox1_CreateTextBlock(object sender, Telerik.WinControls.UI.CreateTextBlockEventArgs e)
{
    if (e.TextBlock is TokenizedTextBlockElement)
    {
        e.TextBlock = new MyTokenizedTextBlockElement();
    }
}
 
public class MyTokenizedTextBlockElement : TokenizedTextBlockElement
{
    private RadCheckBoxElement checkBox;
 
    public RadCheckBoxElement CheckBox
    {
        get
        {
            return this.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.checkBox.Checked = true;
        this.Children.Insert(index, this.checkBox);
    }
}
 
private void radButton1_Click(object sender, EventArgs e)
{
    foreach (MyTokenizedTextBlockElement item in this.radAutoCompleteBox1.TextBoxElement.ViewElement.Children)
    {
        if (item.CheckBox.Checked)
        {
            Console.WriteLine(item.Item.Text);
        }
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
AutoCompleteBox
Asked by
Daniel
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or