views:

619

answers:

3

In a ListView control, the focus is on some Item within that control - that is, the control maintains its own internal notion of what is in focus, which can be retrieved using the FocusedItem property.

I would like no items to be focused. In other words, I want the FocusedItem property to set to null. Any idea how I might accomplish this?

+4  A: 

I think, it is

listView1.FocusedItem.Focused=false;

Make sure that listView1.FocusedItem is not null.

(Thanks to brianpeiris for expanding)

Vanuan
It is giving unhandeled exception.
Bad Boy
What exception?
Vanuan
+3  A: 

To expand on Vanuan's answer:

if (listView1.FocusedItem != null)
{
    listView1.FocusedItem.Focused = false;
}

Something tells me that you also want to un-select the item. So, you probably want to do this as well:

if (listView1.SelectedItems.Count != 0)
{
    listView1.SelectedItems[0].Selected = false;
}
brianpeiris
The first one is working. Thank you very much bro.
Bad Boy