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

ListView Checkboxes

1 Answer 283 Views
CheckedListBox
This is a migrated thread and some comments may be shown as answers.
Ervis
Top achievements
Rank 1
Ervis asked on 19 Dec 2012, 12:25 AM
Hi

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
Ervis  

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 20 Dec 2012, 02:32 PM
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,
Plamen
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
CheckedListBox
Asked by
Ervis
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or