iterate in AutoCompleteBox with Checkbox

2 posts, 1 answers
  1. Daniel
    Daniel avatar
    17 posts
    Member since:
    Oct 2013

    Posted 23 Feb 2015 Link to this post

         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);
            }
        }  








  2. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 26 Feb 2015 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top