2

I have created a ListView called listUsers, but for some reason SelectedIndex isn't defined.

enter image description here

And I have set the MultiSelect to false.
enter image description here
It also seems suspicious to me that "False" is bolded. Meaning that it was not default.
This is not what I think I have been experiencing before.


So I find this very strange, and I don't know how to fix it.
I have tried so far (That didn't work):

  • Restarted VS
  • Copied a ListView from other forms, & pasted it on this form
  • Deleted this.listUsers.MultiSelect definition from Designer's code

And none worked.
What is going on?

Additional details:

  • Windows 7 32-bit
  • VS2010
  • Framework 4
SmRndGuy
  • 1,719
  • 5
  • 30
  • 49
  • 2
    No such property exists. – SLaks Dec 03 '13 at 18:29
  • 1
    Such a property does exist, but for the ListView in UI.WebControls. – PaulG Dec 03 '13 at 18:31
  • 2
    Be careful with the MSDN documentation. If you search for ListView, you might not end up with the [Systems.Windows.Forms.ListView](http://msdn.microsoft.com/en-us/library/system.windows.forms.listview(v=vs.110).aspx). The first Google result is the [System.Windows.Controls.ListView](http://msdn.microsoft.com/en-US/library/system.windows.controls.listview(v=vs.110).aspx), a WPF control that has in fact a `SelectedIndex` and `SelectedItem` property. – ChrisK Dec 03 '13 at 18:32
  • 1
    As always, your problem is you're using deprecated technology, when you should be using WPF. BTW, nice archeological SO Avatar. – Federico Berasategui Dec 03 '13 at 18:37

2 Answers2

5

There is no selected index property on ListView in winforms. To get the selected index you can use

listView1.SelectedIndices[0];
  • There isn't? I was almost positive there is!! ...I need a rest. – SmRndGuy Dec 03 '13 at 18:39
  • @SmRndGuy I spent 3 days trying to figure out the problem my visual studio had when I wanted to get the selected item in a list view and then I remembered stackoverflow... Check [this post](http://stackoverflow.com/questions/15091400/get-single-listview-selecteditem) and [this one](http://stackoverflow.com/questions/11324471/select-index-from-listview). They helped me. –  Dec 03 '13 at 18:41
0

For getting the index of a row in ListView I'm using

 int myindex = Listview1.FocusedItem.Index; 

It works.

Ismail Gunes
  • 548
  • 1
  • 9
  • 24