[OCX] Detect If SelectedItem on ListView

A

ALESSANDRO Baraldi

Hi.
I use a ListView on my application.
I need to conditioning an event if on my ListView
is Selected any Items.
I Load Data on it on Form LoadEvent's.
Even if i don't click on ListView checking SelectedItems Value
i read correct one......!!!
I have no Selected any Row, so like a ListBox i'll no have any
value....??

I try like this, but don't work because i always have returned value

If len(Me.Lv.SelectedItems)=0 then......!


Any suggest will be appreciated.
(Sorry about English mistake)
 
A

Alex Dybenko

SelectedItem returns a reference to selected listitem object, which key or
index you can read:

If Me.Lv.object.SelectedItem.key="key1" then ...
 
A

ALESSANDRO Baraldi

Alex Dybenko said:
SelectedItem returns a reference to selected listitem object, which key or
index you can read:

If Me.Lv.object.SelectedItem.key="key1" then ...


Hi Alex.

On my Lv i use Tag instead of Key propery.
I'm not very happy to use OCX, and this is first time, so
probably i don't use correctly the filling system.

Also with no Selection my List return Right value if i check
TAG(Key).
Using ListBox control this problem don't occur......!

Thanks again.
@Alex

I send i part of my Filling Code:

Public Sub ShowMail(strType As String)
Dim rsMail As New ADODB.Recordset

Dim objItem As ListItem
LsVw1.ColumnHeaders.Clear
LsVw1.ListItems.Clear
LsVw1.View = lvwReport

LsVw1.ColumnHeaders.Add , , "Sender", (LsVw1.Width / 4)
LsVw1.ColumnHeaders.Add , , "Subject", (LsVw1.Width / 4)
LsVw1.ColumnHeaders.Add , , "Date", (LsVw1.Width / 4)
LsVw1.ColumnHeaders.Add , , "Size", (LsVw1.Width / 4)
'Query the Database and get all Mail Infos
Set rsMail = Conn.Execute("SELECT * FROM mails " & _
"WHERE State='" & strType & "' ;")
Do Until rsMail.EOF
Set objItem = LsVw1.ListItems.Add()
objItem.Text = rsMail!From '1° Column
objItem.Tag = rsMail!id
objItem.SmallIcon = SelImmag(rsMail!IsAttach)
objItem.SubItems(1) = rsMail!Subject '2° Column
objItem.SubItems(2) = rsMail!Date '3° Column
objItem.SubItems(3) = rsMail!Size '4° Column
rsMail.MoveNext
Loop
Set objItem = Nothing
rsMail.Close
Set rsMail = Nothing
End Sub
 
A

Alex Dybenko

Hi Alex,
then use tag instead of key, also first check is something selected:

if not (Me.Lv.object.SelectedItem is nothing) then
If Me.Lv.object.SelectedItem.tag="someval" then ...
...
end if
end if
 
A

ALESSANDRO Baraldi

Alex Dybenko said:
Hi Alex,
then use tag instead of key, also first check is something selected:

if not (Me.Lv.object.SelectedItem is nothing) then
If Me.Lv.object.SelectedItem.tag="someval" then ...
...
end if
end if


I think someting wrong on my Fill code.
I check the SelectedItem with a cmdButton after fill it.
Your suggest don't work....
mmmm really WORK GOOD
it's the selectedItem that was no Nothing, it return
the last fill value....., so my code enter inside Tag control...!!

Can i DESELECT or clear SelectedItem property after
Fill code....??

Always thanks....!
@Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top