This is a migrated thread and some comments may be shown as answers.
RadListControl
1 Answer 41 Views
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 20 Sep 2013, 03:56 PM
I want to create a custom control (C#) inherited from RadListControl so that my new control will have a click event for the list's items (not the control itself - since, undesirably, the scroll bar triggers the control's event).

Which control event can I override so I can subscribe to the item's double-click event?  I expected an item_added or similar event but don't see one.

I can do this (but it is ugly and doesn't handle new items being added later):
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());
}

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Sep 2013, 01:44 PM
Hello Philip,

Thank you for contacting us.

First I want to say that the VisualItem property should be used only to get information about a particular item. This property will return null when the item is not visible. Also bear in mind that the visual items are shared among different data items.

To achieve the desired functionality you can override the OnDoubleClick method. Here is sample implementation of a class that inherits RadListControl and uses the code to display the clicked item text:
public class MyListControl : RadListControl
{          
    protected virtual void ElementDoubleClick(object sender, MouseEventArgs e)
    {
        RadListDataItem item = ((RadListVisualItem)sender).Data;
        
        MessageBox.Show(item.Text.ToString());
    }
 
    protected override void OnDoubleClick(EventArgs e)
    {
        base.OnDoubleClick(e);
        MouseEventArgs args = (MouseEventArgs)e;
        var element = this.ElementTree.GetElementAtPoint(new Point(args.X, args.Y));
        this.ElementDoubleClick(element, args);
    }
}

I hope this will be useful. Should you have further questions, I would be glad to help.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Asked by
Philip
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or