jack abdallah
Top achievements
Rank 1
jack abdallah
asked on 04 Jan 2012, 07:49 PM
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
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
4 Answers, 1 is accepted
0
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 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:
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).
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).
0
jack abdallah
Top achievements
Rank 1
answered on 18 Jan 2012, 06:23 PM
Hi Ivan,
thanks for the help and the code i will try it and see the result
Best Regards
thanks for the help and the code i will try it and see the result
Best Regards
0
jack abdallah
Top achievements
Rank 1
answered on 19 Jan 2012, 09:33 AM
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.
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.
0
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
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).