1

while searching for an answer, I found out it's an old "bug" in VS !(?) I am using VS2013. I simply don't believe that they didn't correct it, so I have to think it's intentional, or there's something I am not doing right...

I want to use ListBox to dislpay some simple results. I want that list to be read-only, items not selectable and so on. Just a display of a simple array of results.

I use an array as a datasource (lstBox.DataSource = somearray;), which I update by setting DataSource to null, then back to somearray. The problem is - if I set the listBox SelectionMode to "none", list gets stuck and it doesn't refresh anymore. I can't refresh it. If I set list as "disabled" instead, it's showing the results correctly, it's not selectable, no matter what SelectionMode says, but it's all greyed out... Any help on this ?

p.s. from what I've read, even setting datasource to BindingList or BindingSource doesn't rectify this problem...

Nerd Bg
  • 13
  • 4
  • You, probably, will have to override the ControTemplate for `ListBox` to avoid `IsEnabled` greying - http://stackoverflow.com/questions/3751990/how-to-change-disabled-background-color-of-textbox-in-wpf. You can get the original template from [MSDN](https://msdn.microsoft.com/en-us/library/ms754242(v=vs.110).aspx) . Also, nearly duplicate - http://stackoverflow.com/questions/1051215/wpf-listview-turn-off-selection. – Eugene Podskal May 09 '15 at 17:53

2 Answers2

0

SelectionMode does not have a None value in WPF. (although it had in WinForms)

In WPF, if you want to present items without allowing selection, you should use the ItemsControl class instead of the ListBox.

But I'm not sure whether you are using WPF or WinForms by reading your question.

Benlitz
  • 1,952
  • 1
  • 17
  • 30
  • WinForms, ad yes, there is still possible to have selection set as none in Forms... Sadly I am not using WPF but more and more I see it's advantage as I learn c#... – Nerd Bg May 13 '15 at 08:16
  • Then you should remove the **wpf** tag from your question – Benlitz May 13 '15 at 09:16
-1

I fixed this by setting the selection mode to "One" in the "formclosing" event.