Enhancing RadListControl with a checkboxes column

6 posts, 0 answers
  1. Lev
    Lev avatar
    6 posts
    Member since:
    Jun 2010

    Posted 16 Dec 2010 Link to this post

    Hi All,

    I am developing an app on top of Telerik RadControls for WinForms Q3 2010.
    In one of the views an end user would be required to select one or more options from a list. I have used RadListControl for presenting the set of possible options and picking the selected ones. Yet I wish to leverage the user experience by providing a check box next to each selection option and allowing user to select/unselect options by toggling on/off corresponding check boxes as, for example, the Microsoft's ListView control does.
    I have looked at your nice demos and extended RadListVisualItem as shown to have a check box, to follow the state of its Selected property and to set the Data.Selected property upon catching the state changed event from that check box.
    The code makes quite enough sense, yet in runtime when a check box is set, for example, the state changed event is fired twice:
    • first time with the correct information that the check box has been toggled on;
    • second time with the information that the check box has been toggled off (sic!).

    Can anyone please tell why the second event is fired off?
    A working example of how to implement the desired functionality will be also greatly appreciated.

    Thank you in advance for your assistance.

    -- Best regards

  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Dec 2010 Link to this post

    Hi Lev,

    To make sure I am working with your example, are you able to provide a sample (formatting the code with the FormatCode block) and I'll be happy to take a look at it for you.
    Thanks
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Lev
    Lev avatar
    6 posts
    Member since:
    Jun 2010

    Posted 16 Dec 2010 Link to this post

    Hi Richard,

    Thank you very much for your prompt and kind reply.
    This is my code:
    private class CheckBoxRadListItem : RadListVisualItem
    {
        private RadCheckBoxElement m_checkBox = null;
        private RadLabelElement m_label = null;
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadListVisualItem);
            }
        } // ThemeEffectiveType
        static CheckBoxRadListItem()
        {
            RadListVisualItem.SynchronizationProperties.Add(RadListDataItem.SelectedProperty);
            RadListVisualItem.SynchronizationProperties.Add(RadListDataItem.ValueProperty);
        } // static c-tor
        protected override void PropertySynchronized(RadProperty i_property)
        {
            base.PropertySynchronized(i_property);
            Text = String.Empty;
            if (i_property == RadListDataItem.SelectedProperty && m_checkBox.Checked != Selected)
            {
                m_checkBox.ToggleStateChanged -= ToggleStateChanged; // a hack to prevent redundant looping
                m_checkBox.Checked = Selected;
                m_checkBox.ToggleStateChanged += ToggleStateChanged;
            }
            if (i_property == RadListDataItem.ValueProperty)
            {
                m_label.Text = Data.Text;
            }
        } // PropertySynchronized
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            m_checkBox = new RadCheckBoxElement();
            m_checkBox.Margin = new Padding(5, 2, 2, 2);
            m_checkBox.ToggleStateChanged += ToggleStateChanged;
            m_label = new RadLabelElement();
            m_label.StretchHorizontally = true;
            StackLayoutPanel l_row = new StackLayoutPanel();
            l_row.Orientation = Orientation.Horizontal;
            l_row.Children.Add(m_checkBox);
            l_row.Children.Add(m_label);
            Children.Add(l_row);
        } // CreateChildElements
        private void ToggleStateChanged(object i_sender, StateChangedEventArgs i_args)
        {
            Data.Selected = m_checkBox.Checked;
        } // ToggleStateChanged
    } // CheckBoxRadListItem

    I shall deeply appreciate any suggestions :-)

    -- Best regards
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Dec 2010 Link to this post

    Hi Lev,

    I'll have a look as soon as I can and get back to you either way.
    All the best
    Richard
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Dec 2010 Link to this post

    Hi Lev,

    I haven't been able to get this to work as required at the moment. On the selection of the list item, the fire happens only one, but multiple times on the check. I'll keep looking at it for you as I get time and let you know if/when I can get it to work as you need.
    Regards,
    Richard
  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 21 Dec 2010 Link to this post

    Hi,

    Thank you for writing.

    The approach you were using with the previous combo box and list box does 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 your case you should implement also custom business object because of Visial Items recycling.
    For sample solutions you can take a look at our Demo Application or at this forum thread.
    The approach you were following while using the previous combo box and list box does 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 your case you should implement also a custom business object because of the Visual Items recycling.
    For sample solutions, you can take a look at our Demo application or at this forum thread.

    I hope this helps.

    All the best,
    Peter
    the Telerik team
    Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
Back to Top
UI for WinForms is Visual Studio 2017 Ready