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

Adding controls Dynamically

3 Answers 261 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Velkumar
Top achievements
Rank 1
Velkumar asked on 07 Aug 2012, 07:13 AM
Hi, 

How to add controls (Check box, text box) dynamically to listview

3 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 09 Aug 2012, 01:57 PM
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 >>
0
Seshu
Top achievements
Rank 1
answered on 26 Jan 2015, 09:33 PM
Can you add dropdown list to list view as one column? How do you do that?

Thank you
Seshu
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Jan 2015, 12:50 PM
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.

 
Tags
ListView
Asked by
Velkumar
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Seshu
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or