Custom RadCheckedListBox

3 Answers 70 Views
CheckedListBox
Andy
Top achievements
Rank 1
Iron
Andy asked on 12 Nov 2024, 01:29 PM | edited on 12 Nov 2024, 02:45 PM
Hello, How to add other control elements to radcheckedListBox,such as radDropDownList or radTextBox or radLabel, etc., and how do I add them at a specified position?

3 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 14 Nov 2024, 01:12 PM

Hello, Andy,

RadCheckedListBox controls lists items in a list view oferring check boxes to check/uncheck them. Basically, adding controls into other controls is not good practice, for example I am not sure why you need to add dropdownlist into checked list box control. If you need to achieve some custom control, you can create a user control and place there any controls that you need wrapped in the same panel. If you mean to use a simple label, or button I need to know where exactly you would like to appear before suggest to you where to add it. 

So, can you please specify what exactly you are trying to achieve? It would be great if you can provide a picture to illustrate better. Thus, I could be able to suggest the most suitable approach according to the case.

I am looking forward to your reply. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Andy
Top achievements
Rank 1
Iron
answered on 18 Nov 2024, 01:18 PM | edited on 18 Nov 2024, 01:23 PM

Hello, Nadya,

I'm just doing an coding exercise. This is a picture found on the Internet. I want to look like the picture. Could you please provide me with sample code for reference?

0
Nadya | Tech Support Engineer
Telerik team
answered on 19 Nov 2024, 10:09 AM

Hello, Andy,

According to the provided picture, it seems to me that using RadListView control in DetailsView would be more suitable for you instead of using simple RadCheckedListBox. RadListView offers ShowCheckBoxes property which can be used to show checkboxes in each row: Using Checkboxes - WinForms ListView Control - Telerik UI for WinForms

Moreover, RadListView allows you to create and use your own custom visual items. You will be able to create a custom DetailListViewDataCellElement and add DropDownListElement, or text box element, or any other element that you need to display, and use this custom cell instead of the default one in your list control. Please refer to the following article that describes how you can achieve custom cell element: Custom items - WinForms ListView Control - Telerik UI for WinForms

I prepared a sample code snippet for your reference as well. I added a RadDropDownListElement into the CreateChildElements() and showed it in the second column of RadListView. You can use it as a sample and feel free to extend this functionality further to best fit your needs:

private void RadListView1_CellCreating(object sender, ListViewCellElementCreatingEventArgs e)
{
    DetailListViewDataCellElement cell = e.CellElement as DetailListViewDataCellElement;
    if (cell != null && cell.Data.Name == "Column 1")
    {
        e.CellElement = new CustomDetailListViewDataCellElement(cell.RowElement, e.CellElement.Data);
    }
}

public class CustomDetailListViewDataCellElement : DetailListViewDataCellElement
{
    private RadDropDownListElement ddl;

    public CustomDetailListViewDataCellElement(DetailListViewVisualItem owner,
        ListViewDetailColumn column) : base(owner, column)
    {
    }

    protected override void CreateChildElements()
    {
        base.CreateChildElements();

        this.ddl = new RadDropDownListElement(); 
        this.ddl.Items.Add("Item 1");
        this.ddl.Items.Add("Item 2");
        this.Children.Add(this.ddl);
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(DetailListViewHeaderCellElement);
        }
    }

    public override void Synchronize()
    {
        base.Synchronize();
        this.Text = "";
      
    }

    public override bool IsCompatible(ListViewDetailColumn data, object context)
    {
        if (data.Name != "Column 1")
        {
            return false;
        }
        return base.IsCompatible(data, context);
    }
}

I hope this information helps. If you have other questions, please let me know. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Andy
Top achievements
Rank 1
Iron
commented on 19 Nov 2024, 10:56 AM

Thank you so much for your reply.
Tags
CheckedListBox
Asked by
Andy
Top achievements
Rank 1
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Andy
Top achievements
Rank 1
Iron
Share this question
or