Re: Confused about the Selected property of a ListView
From: Zoury (yanick_lefebvre_at_hotmail.com)
Date: 06/01/04
- Next message: Alek Davis: "Re: Security - Best Encryption Tool"
- Previous message: Bob O`Bob: "Re: Locales"
- In reply to: Dale: "Confused about the Selected property of a ListView"
- Next in thread: Dale: "Re: Confused about the Selected property of a ListView"
- Reply: Dale: "Re: Confused about the Selected property of a ListView"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 1 Jun 2004 13:17:21 -0400
Hi Dale!
The last item to be added to the list has its Selected property
automatically set to True AND the SelectedItem property of the list is set
to it. The SelectedItem property of the list returns the item that has the
*focus* in the list. This doesn't garanty that the item is selected though.
So if you want to prevent this you can unselect the last item when you had
it and set the SelectedItem property to Nothing when your done filling the
list.
here's different tests :
'***
' Selects the first item and gives it focus
Option Explicit
Private Sub Form_Load()
Dim i As Long
With ListView1
.View = lvwReport
Call .ColumnHeaders.Add
For i = 1 To 10
Call .ListItems.Add(, , "item " & i)
Next i
End With
End Sub
'***
'***
' Selects the first item and without giving it the focus
<snip>
For i = 1 To 10
Call .ListItems.Add(, , "item " & i)
Next i
Set .SelectedItem = Nothing
<snip>
'***
'***
' Do not selects any item but gives focus to the first one..
<snip>
For i = 1 To 10
.ListItems.Add(, , "item " & i).Selected = False
Next i
<snip>
End Sub
'***
'***
' Do not selects any items and doesn't give focus to any of them..
<snip>
For i = 1 To 10
.ListItems.Add(, , "item " & i).Selected = False
Next i
Set .SelectedItem = Nothing
<snip>
End Sub
'***
-- Best Regards Yanick Lefebvre "Dale" <dale0610@hotmail.com> a écrit dans le message de news:OJThnc0REHA.904@TK2MSFTNGP12.phx.gbl... > Hi, dumb question, I have a listview on my form which I manually > populate. When it is loaded, I see the first row is selected which is > not what I was expecting - I was expected nothing to be selected ... do > I have to manually set the Selected flag to False for all the items if I > want nothing selected upon loading? Thanks.
- Next message: Alek Davis: "Re: Security - Best Encryption Tool"
- Previous message: Bob O`Bob: "Re: Locales"
- In reply to: Dale: "Confused about the Selected property of a ListView"
- Next in thread: Dale: "Re: Confused about the Selected property of a ListView"
- Reply: Dale: "Re: Confused about the Selected property of a ListView"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|