3 Replies - 11585 Views - Last Post: 22 February 2009 - 12:35 PM Rate Topic: -----

#1 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Unselect Item from Listview in WPF

Posted 21 February 2009 - 10:42 PM

Hi, I'm new @ these stuff and need help..

Basically I have a listview in a WPF app.

When one item, in the listview, is clicked, it is selected.

I want to unselect the item when (1) it is clicked again or (2) user clicks into an empty area of the listview.

I've looked into getitemat, but turns out listview does not have that in WPF. I've posted a thread asking about GetItemAt separately, but haven't had any proper info so far.

Can anyone please advise on what I need to do.

Thanks

This post has been edited by Ameel: 21 February 2009 - 10:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Unselect Item from Listview in WPF

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Unselect Item from Listview in WPF

Posted 21 February 2009 - 10:59 PM

As a solution, you may change the SelectionMode for the ListView to Multiple. This way, when you click on a list item the first time, it selects it. When you click it the second time, it will deselect the item. However, this will enable the user to select multiple items in the ListView.
Was This Post Helpful? 0
  • +
  • -

#3 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Unselect Item from Listview in WPF

Posted 21 February 2009 - 11:29 PM

I'm using extended as selectionmode

Besides, multiple selectionmode does not unselect when user clicks empty space.
Was This Post Helpful? 0
  • +
  • -

#4 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Unselect Item from Listview in WPF

Posted 22 February 2009 - 12:35 PM

kk. I got this to work

		Dim fe As FrameworkElement = TryCast(e.OriginalSource, FrameworkElement)

		Dim lvi As ListViewItem = TryCast(listviewmain.ItemContainerGenerator.ContainerFromItem(fe.DataContext), ListViewItem)
		If lvi Is Nothing Then
			listviewmain.UnselectAll()
		End If


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1