1

Can I change the SelectedItem of ListBox by SelectedIndex? Currently SelectedItem is the observer of SelectedIndex.

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
Javidan Guliyev
  • 227
  • 5
  • 13
  • Is this a homework question? It is ok if it is but you need to tag it appropriately. – Chris Porter Nov 23 '11 at 06:14
  • There is no information about it in web,if i could find anything i will not ask question here.But all is ok,you can delete this – Javidan Guliyev Nov 23 '11 at 06:17
  • @ChrisPorter,can you see http://stackoverflow.com/questions/8131818/intellisense-doesnt-work-for-mvvm-light-toolkit (answer's last comment) i dont want to reask again,but i have no time – Javidan Guliyev Nov 23 '11 at 06:37
  • I can see the comment and it looks like adcool2007 has answered it for you with an edit to his answer. – Chris Porter Nov 23 '11 at 15:00

3 Answers3

5

Yes. Based on the limited info in your question, I think you would need to set up two-way bindings from your listbox's SelectedItem property to a property in your ViewModel.

If you need more info, please provide some more code and I'll take a look.

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
2

If I understand your question correct the answer is: Yes. If you set SelectedIndex in your code then SelectedItem will change accordingly.

If I have not understood your question, please explain further.

Björn
  • 3,098
  • 2
  • 26
  • 40
1

SelectedIndex reflects the index of the item being selected and SelectedItem reflects the selected item itself. So a changes to one of them will change the other one as well.

Fischermaen
  • 12,238
  • 2
  • 39
  • 56