ListView Checkboxes

2 posts, 0 answers
  1. Ervis
    Ervis avatar
    5 posts
    Member since:
    Oct 2012

    Posted 18 Dec 2012 Link to this post


    I have a ListView in IconViewMode with enabled checkboxes. I need to enable and disable the checkboxes themselves based on some requirments.

    I have managed to disable but keep them visible  using the VisualItemFormatting method and turning the ToggleElement.Enabled to false

    I am having a problem accessing the ToggleElement from anywhere else.
    I need to access the checkbox itself the element from SelectedIndexChanged or CurrentItemChanged or any such methods.

    Any help please ?

    Thank you
  2. Plamen
    Plamen avatar
    132 posts

    Posted 20 Dec 2012 Link to this post

    Hello Ervis,

    Thank you for writing.

    RadListView uses virtualization for its VisualItems. For editing a VisualItem you must use VisualItemFormatting and/or VisualItemCreating events. Not all VisualItem objects can be visible at the same time in the RadListView estate area in your application. This is why only the visual items that can be shown in the estate area get created. These visual elements are reused during scrolling, filtering and other operations in the list, which dramatically improves the performance and memory footprint as only a small number of visual items is created. This is the reason, why a ToggleElement can not be access from another event.

    To achieve your scenario, you can add some value to the data items' Tag and in the formatting event check this value and style the item accordingly:
    void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
        if (e.VisualItem.Data.Tag != null && (bool)e.VisualItem.Data.Tag == true)
            e.VisualItem.ToggleElement.Enabled = false;
    void radListView1_CurrentItemChanged(object sender, ListViewItemEventArgs e)
        e.Item.Tag = true;

    I hope this information helps. Do not hesitate to contact us, if you have additional questions.

    Kind regards,
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. DevCraft R3 2016 release webinar banner
Back to Top