
Emanuel Varga
Top achievements
Rank 1
Emanuel Varga
asked on 31 Aug 2010, 09:49 AM
Hello,
In the old ListControl i was using the item.Visibility Collapsed to hide some items while some conditions are not met, in the new version with the DropDownList i've noticed that the visibility property no longer applies to the item, it applies to the visual item, and it no longer works as before, and even more than this the IsVisible property of the item is readOnly, can someone please tell me how should i hide an item and not leave a blank space in the list ?
Thank you very much,
Best Regards,
Emanuel Varga
In the old ListControl i was using the item.Visibility Collapsed to hide some items while some conditions are not met, in the new version with the DropDownList i've noticed that the visibility property no longer applies to the item, it applies to the visual item, and it no longer works as before, and even more than this the IsVisible property of the item is readOnly, can someone please tell me how should i hide an item and not leave a blank space in the list ?
Thank you very much,
Best Regards,
Emanuel Varga
5 Answers, 1 is accepted
0

Niklas
Top achievements
Rank 1
answered on 01 Sep 2010, 07:41 AM
I got the same problem...
//Niklas
//Niklas
0
Accepted
Hello Emanuel Varga, Niklas,
Thank you for writing.
The approach you were using with the previous combo box and list box do not work with RadListControl and RadDropDownList because of the newly introduced UI virtualization. Now the UI items are transient and you can not rely directly on them to set their state as they are sometimes recreated and/or recycled.
In order to hide items that do not match your criteria you should use the filtering feature. You simply set a Predicate<RadListDataItem> method that you have defined to the Filter property of RadDropDownList. This method will be called for every item in your drop down list and the items for which you return false from the predicate will be hidden from view.
Write again if you need further assistance.
Kind regards,
Victor
the Telerik team
Thank you for writing.
The approach you were using with the previous combo box and list box do not work with RadListControl and RadDropDownList because of the newly introduced UI virtualization. Now the UI items are transient and you can not rely directly on them to set their state as they are sometimes recreated and/or recycled.
In order to hide items that do not match your criteria you should use the filtering feature. You simply set a Predicate<RadListDataItem> method that you have defined to the Filter property of RadDropDownList. This method will be called for every item in your drop down list and the items for which you return false from the predicate will be hidden from view.
Write again if you need further assistance.
Kind regards,
Victor
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0

Jason Parrish
Top achievements
Rank 1
answered on 07 Dec 2010, 10:29 PM
Can you provide an example?
0

Emanuel Varga
Top achievements
Rank 1
answered on 08 Dec 2010, 03:57 PM
Hello Jason,
Please take a look at the following example:
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
Please take a look at the following example:
using
System;
using
System.Collections.Generic;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
public
partial
class
Form1 : Form
{
private
RadListControl radListControl1;
private
List<
string
> availableItems =
new
List<
string
>
{
"a1"
,
"a2"
,
"a3"
,
"b1"
,
"b2"
,
"c1"
};
private
List<
string
> selectionItems =
new
List<
string
>
{
"a"
,
"b"
,
"c"
};
private
RadDropDownList radDropDownList;
public
Form1()
{
InitializeComponent();
this
.Controls.Add(radListControl1 =
new
RadListControl());
radListControl1.Dock = DockStyle.Fill;
radListControl1.Filter += OnListFilter;
this
.Controls.Add(radDropDownList =
new
RadDropDownList());
radDropDownList.Dock = DockStyle.Top;
radDropDownList.SelectedValueChanged +=
new
EventHandler(radDropDownList_SelectedValueChanged);
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
radDropDownList.DataSource = selectionItems;
radListControl1.DataSource = availableItems;
}
private
bool
OnListFilter(RadListDataItem item)
{
return
!
string
.IsNullOrEmpty(radDropDownList.SelectedText) && item.Text.Contains(radDropDownList.SelectedText);
}
void
radDropDownList_SelectedValueChanged(
object
sender, EventArgs e)
{
radListControl1.Rebind();
}
}
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Accepted
Hi Jason,
As you can see in the code snippet above, you can handle the VisualListItemFormatting event and set item Item visibility to collapsed depending on a custom condition. In case you decide to follow this approach, you should also set AutoSizeItems to true as well.
I hope this helps.
Peter
the Telerik team
Thank you for writing.
You can also use the following quick solution to hide a particular item:
this
.radDropDownList1.VisualListItemFormatting +=
new
VisualListItemFormattingEventHandler(radDropDownList1_VisualListItemFormatting);
this
.radDropDownList1.AutoSizeItems =
true
;
void
radDropDownList1_VisualListItemFormatting(
object
sender, VisualItemFormattingEventArgs args)
{
if
(args.VisualItem.Data.RowIndex == 2)
//collapse the element with index 2
args.VisualItem.Visibility = ElementVisibility.Collapsed;
}
As you can see in the code snippet above, you can handle the VisualListItemFormatting event and set item Item visibility to collapsed depending on a custom condition. In case you decide to follow this approach, you should also set AutoSizeItems to true as well.
I hope this helps.
Kind regards,
Peter
the Telerik team