radlistview loop through customvisualitems

5 posts, 0 answers
  1. jack abdallah
    jack abdallah avatar
    12 posts
    Member since:
    Feb 2010

    Posted 04 Jan 2012 Link to this post

    Hi is there a way to loop through listview customvisualitems and reach lightvisualelements in order to set visiblity for example
    structure of my listview goes like that :
    radlistview ---->customvisualitem---->stacklayoutpanel---->lightvisualelement1,lighvisualelement2
    so my problem is that i need the right code in order to reach lightvisualelements and apply action on them.
    if there any code that helps i appreciate help .
    Best Regards, jack
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 06 Jan 2012 Link to this post

    Hi Jack,

    Thank you for your question.

    Yes, there is a way to loop through the visual items, but generally, this is not the correct approach of setting their properties. Due to the virtualization mechanism of RadListView, the visual items are reused for displaying different data items. In addition, not all data items have a visual one at a given moment, only the ones that are in the visible area of the control.

    I am not sure what the exact scenario is, but you might find the VisualItemFormatting event useful. You can also use the following method to get the visual item of a certain data item:
    this.radListView1.ListViewElement.ViewElement.GetElement(this.radListView1.Items[0]);

    This method will return null if the data item is not in the visible area of the control.

    You can use the following approach to loop through all the visual items:
    foreach (RadElement element in this.radListView1.ListViewElement.ViewElement.ViewElement.Children)
    {
        CustomListViewVisualItem visualItem = element as CustomListViewVisualItem;
    }

    Again, please note that this is not a good approach since those visual items change their data items very often when you are scrolling up and down.

    There are other approaches as well that involve overriding some of the methods of the custom visual item class, but I cannot suggest you one since I am not aware of the exact use case. If you describe your requirements in detail, I can suggest you which approach to use and also provide you with sample source code.

    Do not hesitate to write back if you need further assistance.

    Kind regards,
    Ivan Todorov
    the Telerik team

    SP1
    of Q3’11 of RadControls for WinForms is available for download (see what's new).
  3. UI for WinForms is Visual Studio 2017 Ready
  4. jack abdallah
    jack abdallah avatar
    12 posts
    Member since:
    Feb 2010

    Posted 18 Jan 2012 Link to this post

    Hi Ivan,
    thanks for the help and the code i will try it and see the result
    Best Regards
  5. jack abdallah
    jack abdallah avatar
    12 posts
    Member since:
    Feb 2010

    Posted 19 Jan 2012 Link to this post

    i have worked on code you suggested and it was just what i need thanks ivan.
    the exact use case for the code was that i needed to filter items but by showing and hiding items instead of resorting items and using filter descriptors Upon client request.

  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 20 Jan 2012 Link to this post

    Hi jack,

    I am glad I could help. Do not hesitate to contact us, if you have other questions.

    Kind regards,
    Ivan Todorov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top
UI for WinForms is Visual Studio 2017 Ready