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

Select an Item in ListBox Control on MouseDown Event

1 Answer 1148 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy
Top achievements
Rank 1
Andy asked on 29 Nov 2011, 01:03 AM
When using the standard listbox control i use the IndexFromPoint Method to get the item at the point of the mouse click...
like...

private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
    int index = listBox1.IndexFromPoint(e.Location);
    listBox1.SelectedIndex = index;
}
is a there a way to do such with a RadListControl?

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 01 Dec 2011, 05:49 PM
Hello Andy,

Thank you for writing and for the provided code snippet.

To achieve the same functionality using the RadListControl, you should use the following code:

private void radListControl1_MouseDown(object sender, MouseEventArgs e)
{
  RadElement element = this.radListControl1.ElementTree.GetElementAtPoint(e.Location);
 
  if (!(element is RadListVisualItem))
  {
    element = element.FindAncestor<RadListVisualItem>();
  }
 
  if (element != null)
  {
    RadListDataItem item = ((RadListVisualItem)element).Data;
    this.radListControl1.SelectedItem = item;
  }
}

I hope you will find this useful. Please note that we are still expecting an answer from your on the questions asked in your thread: "unable to clear multiple selected dates". This will allow us to continue supporting your enquiries.

Best wishes,
Ivan Petrov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Andy
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or