ShowCheckBoxes per ListViewItem?

3 posts, 0 answers
  1. KKL
    KKL avatar
    15 posts
    Member since:
    Nov 2016

    Posted 02 Jul Link to this post

    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. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 03 Jul Link to this post

    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.
  3. KKL
    KKL avatar
    15 posts
    Member since:
    Nov 2016

    Posted 03 Jul in reply to Dimitar Link to this post

    That's perfect - thank you.
Back to Top