What event fires on multiselect ?

5 posts, 2 answers
  1. Art
    Art avatar
    54 posts
    Member since:
    Dec 2010

    Posted 15 Mar 2011 Link to this post

    I have a listcontrol set to MultiExtended. When the user clicks on an item the SelectedIndexChanged event fires. However, if the user holds the shift key down and clicks another item, selecting all items between clicks, the event does not fire.  I need to know that the user just added items to the SelectedItems list. What event can I use?  Thanks

    Later
    Art
  2. jtedrow
    jtedrow avatar
    1 posts
    Member since:
    Sep 2012

    Posted 16 Mar 2011 Link to this post

    The only icky way I have been able to overcome this issue would be to catch the KeyUp/MouseUp events on the box to check for selection change.

    Is there a better way than this?  I am having the same issue as Art, where the event will not fire for Shift+Click selections with MultiExtended enabled.

    Private Sub lstIncludedFields_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstIncludedFields.KeyUp
        'Do Code here for selection changed
    End Sub


    This becomes very slow however with large lists.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Mar 2011 Link to this post

    Hello Art, 

    Something like this is what you need I think. Please let me know if that helps, or if you need more information

    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (RadListDataItem item in this.radListControl1.Items)
        {
            item.RadPropertyChanged += new Telerik.WinControls.RadPropertyChangedEventHandler(item_RadPropertyChanged);
        }
    }
     
    void item_RadPropertyChanged(object sender, Telerik.WinControls.RadPropertyChangedEventArgs e)
    {
        if (e.Property.Name == "Selected")
        {
            RadListDataItem item = (RadListDataItem)sender;
            MessageBox.Show(item.Text + " selected = " + item.Selected.ToString());
        }
    }

    Regards, 
    Richard
  5. Art
    Art avatar
    54 posts
    Member since:
    Dec 2010

    Posted 16 Mar 2011 Link to this post

    Could you send that code in VB, although I have to admit I wil probably just use a VB ListBox, as it's selectionchanged event fires on multiselects.
  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Mar 2011 Link to this post

    Hello Art,

    here is the code in VB. Do let me know if that helps, or indeed if you have any difficulties.

    Private Sub Form1_Load(sender As Object, e As EventArgs) handles Form1.Load
        For Each item As RadListDataItem In Me.radListControl1.Items
      
            AddHandler item.RadPropertyChanged, AddressOf item_RadPropertyChanged
        Next
    End Sub
      
    Private Sub item_RadPropertyChanged(sender As Object, e As Telerik.WinControls.RadPropertyChangedEventArgs)
        If e.Property.Name = "Selected" Then
            Dim item As RadListDataItem = DirectCast(sender, RadListDataItem)
            MessageBox.Show(item.Text & " selected = " & item.Selected.ToString())
        End If
    End Sub

    All the best
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready