WPF ListView Programmatically Select Item?

Bind the IsSelected property of the ListViewItem to a property on your model. Then, you need only work with your model rather than worrying about the intricacies of the UI, which includes potential hazards around container virtualization For example: ListView.

Bind the IsSelected property of the ListViewItem to a property on your model. Then, you need only work with your model rather than worrying about the intricacies of the UI, which includes potential hazards around container virtualization. For example: Now, just work with your model's IsGroovy property to select/deselect items in the ListView.

1 But of course. Databinding. Don't all problems in WPF boil down at some point to databinding?

Thanks, Kent. – Paul Prewett Jul 1 '09 at 15:52 This is a really neat solution, kudos! – Baboon Apr 22 at 14:52.

Here would be my best guess, which would be a much simpler method for selection. Since I'm not sure what you're selecting on, here's a generic example: var indices = new List(); for(int I = 0; I Contains("foo") ) indices. Add(i); } // Reset the selection and add the new items.

LstVariable_All.SelectedIndices.Clear(); foreach(int index in indices) { lstVariable_All.SelectedIndices. Add(index); } What I'm used to seeing is a settable SelectedItem, but I see you can't set or add to this, but hopefully this method works as a replacement.

 So when I click on a data point in my graph I have it selected in the listview and vice versa.To accomplish this I have a separate observablecollection that contains my currently selected items.  Now my usercontrol that contains the listview has a bunch of dependencies one of which is this observable collection.  So for that dependency I have a propertyChangedCallback that gets triggered whenever I add/remove items from that collection.

 In there I traverse my listview. Selecteditems list and remove any items that are there but not in my selected collection (this takes care of items that are clicked again thus removing them) then I traverse my selected collection and force the listview to select itlistView.SelectedItems. Add(obj) this works for me as bothe the itemssource on the list is the same type of data as in the selected collection, the list view gets templated later as you do but that does not matter for me as im comparing actual source data rather than the templated data.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions