Adding controls Dynamically

4 posts, 0 answers
  1. Velkumar
    Velkumar avatar
    16 posts
    Member since:
    Jul 2012

    Posted 07 Aug 2012 Link to this post

    Hi, 

    How to add controls (Check box, text box) dynamically to listview
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 09 Aug 2012 Link to this post

    Hello Velkumar,

    Thank you for writing.

    You can see an example on how to add elements to a ListViewItem in our online documentation. List view items have build in check boxes, you can read more on how to use them again in our documentation.

    I hope this will be useful. Should you have further questions, I would be glad to help.
     
    Regards,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Seshu
    Seshu avatar
    3 posts
    Member since:
    Nov 2012

    Posted 26 Jan 2015 in reply to Ivan Petrov Link to this post

    Can you add dropdown list to list view as one column? How do you do that?

    Thank you
    Seshu
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 29 Jan 2015 Link to this post

    Hello Seshu,

    Thank you for contacting us.

    If I understand your requirement correctly, you are trying to display drop down list for a specific column. For this purpose, you can use a custom DetailListViewDataCellElement and override the CreateChildElements where you can add a RadDropDownListElement to the Children collection. The result from the following code snippet is illustrated on the attached screenshot:
    private void radListView1_CellCreating(object sender, ListViewCellElementCreatingEventArgs e)
    {
        DetailListViewDataCellElement cell = e.CellElement as DetailListViewDataCellElement;
        if (cell != null && cell.Data.Name == "Title")
        {
            e.CellElement = new CustomDetailListViewDataCellElement(cell.RowElement, e.CellElement.Data);
        }
    }

    public class CustomDetailListViewDataCellElement : DetailListViewDataCellElement
    {
        private RadDropDownListElement dropdown;
     
        public CustomDetailListViewDataCellElement(DetailListViewVisualItem owner,
            ListViewDetailColumn column) : base(owner, column)
        {
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
     
            this.dropdown = new RadDropDownListElement();
            this.dropdown.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
            this.dropdown.DataSource = new List<string>() { "one", "two", "three" };
            this.Children.Add(this.dropdown);
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(DetailListViewHeaderCellElement);
            }
        }
     
        public override void Synchronize()
        {
            base.Synchronize();
            this.Text = "";
        }
    }

    Note that RadDropDownListElement hosts the MS TextBox if the DropDownStyle property is set to DropDown. Using controls in RadListView cells may slow down the scrolling and will cause visual glitches as they do not support clipping. A better option would be using custom editors. Please refer to ListView >> Checkboxes and editors help article >> Switching Editors section.

    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.

     
Back to Top