Hello Mohammad,
I have moved your latest question
from this thread as it is a different topic and needs a new forum thread.
Here are three ways you can accomplish what you're looking for. I recommend option #1, but depending on what you're try to use the index for you might find the other options more suitable.
First, make sure you're hooked into the MouseUp event:
Here's the handler for MouseUp:
private
void
RadListView1_OnMouseUp(
object
sender, MouseEventArgs e)
{
if
(e.Button == MouseButtons.Right)
{
// Get the VisualItem, you can use the base class (BaseListViewVisualItem) or your custom item (MyCustomVisualItem)
var visualItem = radListView1.ElementTree.GetElementAtPoint(e.Location)
as
BaseListViewVisualItem;
// Get the data from the visual item
var dataItem = visualItem?.Data;
if
(dataItem ==
null
)
return
;
//***** Three approaches to get index ********//
// ---- Approach 1 (recommended) ---- //
// Get the index of the item in the RadListView
var index = radListView1?.Items?.IndexOf(dataItem);
// ---- Approach 2 ---- //
// Get the index of the item in the bound collection
// Get the DataBoundItem
//var employee = dataItem?.DataBoundItem as Employee;
//if (employee == null) return;
// Get the index of the item int he original datasource
//var index = employees.FindIndex(em => em == employee);
// ---- Approach 3 ---- //
// select the item programmatically and get SelectedIndex
//radListView1.SelectedItem = dataItem;
//var index = radListView1.SelectedIndex;
//*********************************************//
Debug.WriteLine($
"SelectedIndex is: {index}"
);
}
}
Please let us know if you have any further questions or conerns. Thank you for contacting Telerik Support.
Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this
blog post and share your thoughts.