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

DropDownList and item visibility broken?

3 Answers 134 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Francois
Top achievements
Rank 1
Francois asked on 02 Nov 2011, 03:29 PM
Hi, I'm using the latest version of the WinControls package and I'm using trying to hide inactive data on a DropDownList to prevent the user from selecting it but ElementVisibility.Collapsed shows a blank line (as ElementVisibility.Hidden). It is my understanding that the row should not visible nor blank with the first value.

Am i missing something?


private void uxAssignedAt_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
    var personne = args.VisualItem.Data.DataBoundItem as Personne;
 
    // Reset default value
    args.VisualItem.ResetValue(LightVisualElement.VisibilityProperty, ValueResetFlags.Local);
 
    if (personne != null && !personne.IndActive)
    {
        args.VisualItem.Visibility = ElementVisibility.Collapsed;
    }
}

3 Answers, 1 is accepted

Sort by
0
Francois
Top achievements
Rank 1
answered on 03 Nov 2011, 06:44 PM
Do anyone else have this behavior?
0
Accepted
Stefan
Telerik team
answered on 07 Nov 2011, 10:00 AM
Hello Francois,

Thank you for writing.

Setting the VisualElement Visibility property is not a valid scenario since the control is virtualized and each visual item might display different data items. Thus, I will recommend to set the data item Enabled property to false. With this setting, the item will display as disabled, and it will be skipped while navigating with the keyboard. The best place to introduce such a setting is in the ItemDataBound event handler:
void radDropDownList1_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
    if (!((Personne)args.NewItem.DataBoundItem).IndActive)
    {
        args.NewItem.Enabled = false;
    }
     
}

As I mentioned in the other forum thread, we still have to cover the case with the selection using the MouseWheel and we will do our best in order to provide a fix in the upcoming release (expected in the middle of the month).

Meanwhile, you can cover this case by setting the EnableMouseWheel to false, and using the following code in the MouseWheel event handler:
radDropDownList1.DropDownListElement.MouseWheel += new MouseEventHandler(radDropDownList1_MouseWheel);
//....   
void radDropDownList1_MouseWheel(object sender, MouseEventArgs e)
{
    if (e.Delta < 0)
    {
        radDropDownList1.SelectedIndex++;
        while (!radDropDownList1.SelectedItem.Enabled )
        {
            radDropDownList1.SelectedIndex++;
        }
    }
    else
    {
        if (radDropDownList1.SelectedIndex - 1 >= 0)
        {
            radDropDownList1.SelectedIndex--;
            while (!radDropDownList1.SelectedItem.Enabled)
            {
                radDropDownList1.SelectedIndex--;
            }
        }
    }
}

I hope that you find this information useful.

Kind regards,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Francois
Top achievements
Rank 1
answered on 07 Nov 2011, 05:15 PM
Thank you, I'm looking forward the next version.
Tags
DropDownList
Asked by
Francois
Top achievements
Rank 1
Answers by
Francois
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or