Manish Parmar
Manish Parmar

Reputation: 859

how can i get value of the selected index on double click of the listview of winform?

How can i can the Selected index of the listview when i double click on selected item ?

Also i have created a event DragEnter for the listview but due to this the double click event

is not firing.

So is there any Idea regarding the same ?

thanks in advance. Manish.

Upvotes: 1

Views: 5310

Answers (2)

Hans Olsson
Hans Olsson

Reputation: 54999

If I understand correctly you want to know the Index of the item that was double clicked, you can do this by handling the MouseDoubleClick event and adding this code in the handler:

int index = listView1.HitTest(e.Location).Item.Index;

Upvotes: 2

Hemant
Hemant

Reputation: 19826

Below works fine for me (even with DragEnter event handler):

private void listView1_DoubleClick (object sender, EventArgs e) {
    if (listView1.SelectedIndices.Count > 0)
        MessageBox.Show ("Selected Index is " + listView1.SelectedIndices[0]);
    else
        MessageBox.Show ("No item selected");
}

Upvotes: 2

Related Questions