DropDownList and item visibility broken?

4 posts, 1 answers
  1. Francois
    Francois avatar
    52 posts
    Member since:
    Dec 2010

    Posted 02 Nov 2011 Link to this post

    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;
        }
    }
  2. Francois
    Francois avatar
    52 posts
    Member since:
    Dec 2010

    Posted 03 Nov 2011 Link to this post

    Do anyone else have this behavior?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 07 Nov 2011 Link to this post

    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.

  5. Francois
    Francois avatar
    52 posts
    Member since:
    Dec 2010

    Posted 07 Nov 2011 Link to this post

    Thank you, I'm looking forward the next version.
Back to Top