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

List Control Double Click Event.

10 Answers 391 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
Khizar Khan
Top achievements
Rank 1
Khizar Khan asked on 17 Feb 2011, 06:44 PM
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

10 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 17 Feb 2011, 09:53 PM
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
0
Khizar Khan
Top achievements
Rank 1
answered on 18 Feb 2011, 11:57 AM
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
0
Richard Slade
Top achievements
Rank 2
answered on 18 Feb 2011, 12:11 PM
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
0
Peter
Telerik team
answered on 23 Feb 2011, 08:01 AM
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
0
Juergen Holzer
Top achievements
Rank 2
answered on 08 Jun 2011, 05:39 PM
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
0
Peter
Telerik team
answered on 13 Jun 2011, 02:57 PM
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.
0
Juergen Holzer
Top achievements
Rank 2
answered on 14 Jun 2011, 10:32 AM
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
0
Martin Vasilev
Telerik team
answered on 16 Jun 2011, 05:02 PM
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.
0
Juergen Holzer
Top achievements
Rank 2
answered on 20 Jun 2011, 09:38 AM
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
0
Martin Vasilev
Telerik team
answered on 22 Jun 2011, 04:33 PM
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.
Tags
ListControl
Asked by
Khizar Khan
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Khizar Khan
Top achievements
Rank 1
Peter
Telerik team
Juergen Holzer
Top achievements
Rank 2
Martin Vasilev
Telerik team
Share this question
or