List Control Double Click Event.

11 posts, 1 answers
  1. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 17 Feb 2011 Link to this post

    Hi,

    I have list control with data on a user control.

    I have subscribed for a double click event for a listcontrol.

    as there are lot of items in the controls, when the user clicking on scroll bar to go donw the list. it is firing the double click event and thus selecting the wrong item, instead of continue scrolling down as the click was on the scroll bar and not on the item.

    please advice.

    Regards,
    khizar
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 17 Feb 2011 Link to this post

    Hello,

    Instead of subscribing to the double click event of the RadListControl, subscribe to the MouseDoubleClick event. This will allow you to get the mouse position and therefore the element at the point.

    this.radListControl1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.radListControl1_MouseDoubleClick);
    private void radListControl1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        RadListVisualItem clickedItem = radListControl1.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
        if (clickedItem != null)
        {
            RadListDataItem dataItem = clickedItem.Data;
            MessageBox.Show(dataItem.Text);
        
    }

    hope that helps but let me know if you have any questions
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 18 Feb 2011 Link to this post

    Thanks For your help,

    I had to add few more lines before casting to RadListVisualElement.

    object aObject = (Object)rListBox1.ElementTree.GetElementAtPoint(e.Location);
     
     if (aObject.GetType() != typeof(RadListVisualItem))
     {
         return;
     }

    As it was throwing cast exceptions. attached are the files. Hope this is of help to others.

    can you please fix these in your future releases.

    Regards,
    Khizar
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 18 Feb 2011 Link to this post

    Hello,

    I'm glad that helped. Unfortunatly, I'm not part of the Telerik development team

    There is a second way to add a double click event handler too which you may be interested in

    foreach (RadListDataItem item in this.RadListControl1.Items) {
        item.VisualItem.DoubleClick += Item_DoubleClick;
    }

    private void Item_DoubleClick(object sender, EventArgs e)
    {
        RadListDataItem item = ((RadListVisualItem)sender).Data;
        MessageBox.Show(item.Text.ToString());
    }

    Hope that helps
    Richard
  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 23 Feb 2011 Link to this post

    Hi Khizar,

    Thank you for sharing your solution with community. 

    ElementTree's GetElementAtPoint returns any Telerik Object under the mouse cursor and user should cast the object according to the context. You can use Richard's solution.

    Do not hesitate to contact us if you have other questions.

    Kind regards,
    Peter
    the Telerik team
  7. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 08 Jun 2011 Link to this post

    Hello!

    I want the MouseDoubleClick-Event to be added at runtime for each item I'm adding to the List. The problem is, I'm creating the list while it is initialized in Form_Load or Form_Shown event. At this time VisualItem is Null so I get a NullPointerException. Is there another way to add the MouseDoubleClick-Event to each item while runtime?

    Kind regards
    Juergen
  8. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 13 Jun 2011 Link to this post

    Hi Juergen,

    Thank you for writing.

    I would like to suggest using CreatingVisualListItem event for this purpose, for example:

    list.CreatingVisualListItem += new CreatingVisualListItemEventHandler(list_CreatingVisualListItem);
     
     
         void list_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
         {
             args.VisualItem.DoubleClick += new EventHandler(VisualItem_DoubleClick);
         }
     
         void VisualItem_DoubleClick(object sender, EventArgs e)
         {
             throw new NotImplementedException();
         }

    I hope this helps.

    All the best,
    Peter
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  9. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 14 Jun 2011 Link to this post

    Thank you for your reply!
    But with this code I also get a NullPointerException.
    I think the reason is because the list contains more items that can be shown at once and so there is no visualitem available until the is visible.
    Is there a way to change this behavior?

    Regards
    Juergen
  10. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 16 Jun 2011 Link to this post

    Hello Juergen Holzer,

    Thank you for writing.

    It look like the null reference exception is an issue in the CreatingListVisualItem event. It appears that the VisualItem argument is always null. We will address this issue on one of the next releases. For the time being I suggest you to consider the implementation with MouseDoubleClick provided before in this topic.

    I have updated your Telerik points for bringing this issue to our attention. Let me know if you have any other questions.

    Kind regards, Martin Vasilev
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  11. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 20 Jun 2011 Link to this post

    Hello Martin!

    Thank you for your answer and the points!

    I solved the issue using VisualItemFormatting event. At the time it occurs the VisualItem is not null, so I can use it like Peter suggested with the CreatingVisualListItem event.

    Kind regards
    Juergen
  12. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 22 Jun 2011 Link to this post

    Hello Juergen,

    I am glad you have found a suitable solution for your scenario. Do not hesitate to contact us again if you need any additional assistance.

    Kind regards,
    Martin Vasilev
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top
UI for WinForms is Visual Studio 2017 Ready