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

ShowCheckBoxes per ListViewItem?

2 Answers 184 Views
CheckedListBox
This is a migrated thread and some comments may be shown as answers.
KKL
Top achievements
Rank 1
KKL asked on 02 Jul 2017, 07:30 AM

I have a ListView in Details view, with ShowCheckBoxes set to true. As expected, all ListViewItems have checkboxes next to them.

Is it possible to hide (or disable) checkboxes next to certain ListViewItems? 

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 03 Jul 2017, 08:33 AM
Hello Kevin,

Since RadListView is using UI Virtualization you can access the visual elements in the formatting events only. For example, you can use the Tag property of the data item to store information about whether or not an item must have a checkbox. Then you can use it in the formatting event:
public RadForm1()
{
    InitializeComponent();
    radListView1.ShowCheckBoxes = true;
    for (int i = 0; i < 10; i++)
    {
 
        var item = new ListViewDataItem();
        item[0] = "Item" + i;
        item[1] = "Test";
        if (i % 2 == 0)
        {
            item.Tag = "No Checkbox";
        }
        radListView1.Items.Add(item);
    }
    radListView1.VisualItemFormatting += RadListView1_VisualItemFormatting;
 
    new Telerik.WinControls.RadControlSpy.RadControlSpyForm().Show();
 
}
 
private void RadListView1_VisualItemFormatting(object sender, Telerik.WinControls.UI.ListViewVisualItemEventArgs e)
{
    if (e.VisualItem.Data.Tag != null)
    {
        var item = e.VisualItem as DetailListViewVisualItem;
        item.ToggleElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
    }
    else
    {
        var item = e.VisualItem as DetailListViewVisualItem;
        item.ToggleElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
KKL
Top achievements
Rank 1
answered on 03 Jul 2017, 09:24 AM
That's perfect - thank you.
Tags
CheckedListBox
Asked by
KKL
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
KKL
Top achievements
Rank 1
Share this question
or