[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

12/27/2011 9:44:00 PM

I was trying to track down a failure in my code that could not fail
(lol).
I drilled down to a routine that looked perfect but upon stepping
through I found errored at ListSubItems.

Here is the code: (See ' FAILS HERE)
Public Function ListViewRowGet(LVW As ListView, lRow As Long, Optional
bSubTags As Boolean = False, Optional sSep As String = vbTab) As String

On Error GoTo ListViewRowGetErr

' the whole enchilada

Dim lCol As Long

ListViewRowGet = LVW.ListItems(lRow).text

For lCol = 1 To LVW.ColumnHeaders.Count - 1
ListViewRowGet = ListViewRowGet & sSep &
LVW.ListItems(lRow).SubItems(lCol)
If bSubTags Then
ListViewRowGet = ListViewRowGet & sSep &
LVW.ListItems(lRow).ListSubItems(lCol).Tag ' FAILS HERE
End If

Next lCol

ListViewRowGet = ListViewRowGet & sSep & LVW.ListItems(lRow).Tag

ListViewRowGetExit:
Exit Function

ListViewRowGetErr:
Resume ListViewRowGetExit

End Function 'ListViewRowGet

How could this fail? Well it seems that you have to put something into
the
LVW.ListItems(lRow).ListSubItems(lCol).Tag
or it simply does not exist.

I tried
LVW.ListItems(lRow).ListSubItems(lCol).Tag = ""
but that was no good.

so for now I use
LVW.ListItems(lRow).ListSubItems(lCol).Tag = "x"

and it all plays.
I cannot find anything anywhere to support my hypothesis.
Am I nuts (don't answer that) or what other gotchas are there to watch
out for?
Is there a better solution than "x"?

From what I can read, the ListSubItems is an object that needs
instantiation and simply assigning a value does that (without the Set).
Just a little more confused than usual.


8 Answers

ralph

12/27/2011 10:20:00 PM

0

On Tue, 27 Dec 2011 13:44:21 -0800, BeeJ <nospam@spamnot.com> wrote:

>I was trying to track down a failure in my code that could not fail
>(lol).
>I drilled down to a routine that looked perfect but upon stepping
>through I found errored at ListSubItems.
>
>Here is the code: (See ' FAILS HERE)
>Public Function ListViewRowGet(LVW As ListView, lRow As Long, Optional
>bSubTags As Boolean = False, Optional sSep As String = vbTab) As String
>
> On Error GoTo ListViewRowGetErr
>
> ' the whole enchilada
>
> Dim lCol As Long
>
> ListViewRowGet = LVW.ListItems(lRow).text
>
> For lCol = 1 To LVW.ColumnHeaders.Count - 1
> ListViewRowGet = ListViewRowGet & sSep &
>LVW.ListItems(lRow).SubItems(lCol)
> If bSubTags Then
> ListViewRowGet = ListViewRowGet & sSep &
>LVW.ListItems(lRow).ListSubItems(lCol).Tag ' FAILS HERE
> End If
>
> Next lCol
>
> ListViewRowGet = ListViewRowGet & sSep & LVW.ListItems(lRow).Tag
>
>ListViewRowGetExit:
> Exit Function
>
>ListViewRowGetErr:
> Resume ListViewRowGetExit
>
>End Function 'ListViewRowGet
>
>How could this fail? Well it seems that you have to put something into
>the
>LVW.ListItems(lRow).ListSubItems(lCol).Tag
>or it simply does not exist.
>
>I tried
>LVW.ListItems(lRow).ListSubItems(lCol).Tag = ""
>but that was no good.
>
>so for now I use
>LVW.ListItems(lRow).ListSubItems(lCol).Tag = "x"
>
>and it all plays.
>I cannot find anything anywhere to support my hypothesis.
>Am I nuts (don't answer that) or what other gotchas are there to watch
>out for?
>Is there a better solution than "x"?
>
>From what I can read, the ListSubItems is an object that needs
>instantiation and simply assigning a value does that (without the Set).
>Just a little more confused than usual.
>

Quick response.

Such 'oddities' are quit normal with such collections. (And not just
those used with VB.)

This guys are actually Variant Collections of Variant Collections and
are designed to have a flexible structure that can be queried, and
lean or bloated as required. High OO. <g>

-ralph

DanS

12/28/2011 1:01:00 PM

0

BeeJ <nospam@spamnot.com> wrote in
news:jdde7i$q0f$1@speranza.aioe.org:


> For lCol = 1 To LVW.ColumnHeaders.Count - 1
> ListViewRowGet = ListViewRowGet & sSep &
> LVW.ListItems(lRow).SubItems(lCol)
> If bSubTags Then
> ListViewRowGet = ListViewRowGet & sSep &
> LVW.ListItems(lRow).ListSubItems(lCol).Tag

Above I see...

LVW.ListItems(lRow).SubItems(lCol)

.....and also....

LVW.ListItems(lRow).ListSubItems(lCol).Tag



IIRC, .SubItems(lCol) is the Common Controls 5 version
hierarchy and .*List*SubItems(lCol) is the Common Controls 6
callout.

I'm guessing you are using v5 if the .SubItems(lCol) line
didn't error out.

MikeD

12/29/2011 12:33:00 AM

0



"DanS" <t.h.i.s.n.t.h.a.t@r.o.a.d.r.u.n.n.e.r.c.o.m> wrote in message
news:Xns9FC951A31D004thisnthatroadrunnern@216.196.97.131...
> BeeJ <nospam@spamnot.com> wrote in
> news:jdde7i$q0f$1@speranza.aioe.org:
>
>
>> For lCol = 1 To LVW.ColumnHeaders.Count - 1
>> ListViewRowGet = ListViewRowGet & sSep &
>> LVW.ListItems(lRow).SubItems(lCol)
>> If bSubTags Then
>> ListViewRowGet = ListViewRowGet & sSep &
>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>
> Above I see...
>
> LVW.ListItems(lRow).SubItems(lCol)
>
> ....and also....
>
> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>
>
>
> IIRC, .SubItems(lCol) is the Common Controls 5 version
> hierarchy and .*List*SubItems(lCol) is the Common Controls 6
> callout.
>
> I'm guessing you are using v5 if the .SubItems(lCol) line
> didn't error out.
>

The v6 ListView still has the SubItems property...and in a lot of cases,
it's actually easier to work with than a ListSubItem object (i.e. when all
you need is the text). The v5 ListView does NOT have the ListSubItems
collection or the ListSubItem object. I think you just got it backwards.

Mike




BeeJ

12/29/2011 12:36:00 AM

0

DanS explained on 12/28/2011 :
> BeeJ <nospam@spamnot.com> wrote in
> news:jdde7i$q0f$1@speranza.aioe.org:
>
>
>> For lCol = 1 To LVW.ColumnHeaders.Count - 1
>> ListViewRowGet = ListViewRowGet & sSep &
>> LVW.ListItems(lRow).SubItems(lCol)
>> If bSubTags Then
>> ListViewRowGet = ListViewRowGet & sSep &
>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>
> Above I see...
>
> LVW.ListItems(lRow).SubItems(lCol)
>
> ....and also....
>
> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>
>
>
> IIRC, .SubItems(lCol) is the Common Controls 5 version
> hierarchy and .*List*SubItems(lCol) is the Common Controls 6
> callout.
>
> I'm guessing you are using v5 if the .SubItems(lCol) line
> didn't error out.

It is both VB6 and Common Controls 6. Both .SubItems(lCol) and
..*List*SubItems(lCol) are accepted.


DanS

12/29/2011 2:08:00 PM

0

BeeJ <nospam@spamnot.com> wrote in
news:jdgcm0$ajk$1@speranza.aioe.org:

> DanS explained on 12/28/2011 :
>> BeeJ <nospam@spamnot.com> wrote in
>> news:jdde7i$q0f$1@speranza.aioe.org:
>>
>>
>>> For lCol = 1 To LVW.ColumnHeaders.Count - 1
>>> ListViewRowGet = ListViewRowGet & sSep &
>>> LVW.ListItems(lRow).SubItems(lCol)
>>> If bSubTags Then
>>> ListViewRowGet = ListViewRowGet & sSep &
>>> LVW.ListItems(lRow).ListSubItems(lCol).T
>>> ag
>>
>> Above I see...
>>
>> LVW.ListItems(lRow).SubItems(lCol)
>>
>> ....and also....
>>
>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>>
>>
>>
>> IIRC, .SubItems(lCol) is the Common Controls 5 version
>> hierarchy and .*List*SubItems(lCol) is the Common Controls
>> 6 callout.
>>
>> I'm guessing you are using v5 if the .SubItems(lCol) line
>> didn't error out.
>
> It is both VB6 and Common Controls 6. Both .SubItems(lCol)
> and .*List*SubItems(lCol) are accepted.

I see that now.

FWIW, I just created a test project populating a LV with rows
and columns using both .ListSubItems.Add, and using .Subitem
(x) = Text......

....and both ways, I could access the .tag property w/o error,
whether or not the tag was set to anyting.



DanS

12/29/2011 2:12:00 PM

0

"MikeD" <nobody@nowhere.edu> wrote in
news:jdgcff$u1c$1@dont-email.me:

>
>
> "DanS" <t.h.i.s.n.t.h.a.t@r.o.a.d.r.u.n.n.e.r.c.o.m> wrote
> in message
> news:Xns9FC951A31D004thisnthatroadrunnern@216.196.97.131...
>> BeeJ <nospam@spamnot.com> wrote in
>> news:jdde7i$q0f$1@speranza.aioe.org:
>>
>>
>>> For lCol = 1 To LVW.ColumnHeaders.Count - 1
>>> ListViewRowGet = ListViewRowGet & sSep &
>>> LVW.ListItems(lRow).SubItems(lCol)
>>> If bSubTags Then
>>> ListViewRowGet = ListViewRowGet & sSep &
>>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>>
>> Above I see...
>>
>> LVW.ListItems(lRow).SubItems(lCol)
>>
>> ....and also....
>>
>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>>
>>
>>
>> IIRC, .SubItems(lCol) is the Common Controls 5 version
>> hierarchy and .*List*SubItems(lCol) is the Common Controls
>> 6 callout.
>>
>> I'm guessing you are using v5 if the .SubItems(lCol) line
>> didn't error out.
>>
>
> The v6 ListView still has the SubItems property...and in a
> lot of cases, it's actually easier to work with than a
> ListSubItem object (i.e. when all you need is the text).
> The v5 ListView does NOT have the ListSubItems collection
> or the ListSubItem object. I think you just got it
> backwards.

Not backwards.......in any case however, I was just trying to
answer a question that I (thought I) knew the answer to before
being berated for only asking questions. ;)

BeeJ

12/29/2011 9:29:00 PM

0

DanS brought next idea :
> BeeJ <nospam@spamnot.com> wrote in
> news:jdgcm0$ajk$1@speranza.aioe.org:
>
>> DanS explained on 12/28/2011 :
>>> BeeJ <nospam@spamnot.com> wrote in
>>> news:jdde7i$q0f$1@speranza.aioe.org:
>>>
>>>
>>>> For lCol = 1 To LVW.ColumnHeaders.Count - 1
>>>> ListViewRowGet = ListViewRowGet & sSep &
>>>> LVW.ListItems(lRow).SubItems(lCol)
>>>> If bSubTags Then
>>>> ListViewRowGet = ListViewRowGet & sSep &
>>>> LVW.ListItems(lRow).ListSubItems(lCol).T
>>>> ag
>>>
>>> Above I see...
>>>
>>> LVW.ListItems(lRow).SubItems(lCol)
>>>
>>> ....and also....
>>>
>>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>>>
>>>
>>>
>>> IIRC, .SubItems(lCol) is the Common Controls 5 version
>>> hierarchy and .*List*SubItems(lCol) is the Common Controls
>>> 6 callout.
>>>
>>> I'm guessing you are using v5 if the .SubItems(lCol) line
>>> didn't error out.
>>
>> It is both VB6 and Common Controls 6. Both .SubItems(lCol)
>> and .*List*SubItems(lCol) are accepted.
>
> I see that now.
>
> FWIW, I just created a test project populating a LV with rows
> and columns using both .ListSubItems.Add, and using .Subitem
> (x) = Text......
>
> ...and both ways, I could access the .tag property w/o error,
> whether or not the tag was set to anyting.

Strange. Did you not touch the SubItem?
In my case I only touched the .Text, SubItem(1) and itmX.Tag (the row
tag). DId not touch the SubItem(2) or ListSubItem(2).Tag.


DanS

12/31/2011 2:05:00 PM

0

BeeJ <nospam@spamnot.com> wrote in
news:jdim2r$t94$1@speranza.aioe.org:

> DanS brought next idea :
>> BeeJ <nospam@spamnot.com> wrote in
>> news:jdgcm0$ajk$1@speranza.aioe.org:
>>
>>> DanS explained on 12/28/2011 :
>>>> BeeJ <nospam@spamnot.com> wrote in
>>>> news:jdde7i$q0f$1@speranza.aioe.org:
>>>>
>>>>
>>>>> For lCol = 1 To LVW.ColumnHeaders.Count - 1
>>>>> ListViewRowGet = ListViewRowGet & sSep &
>>>>> LVW.ListItems(lRow).SubItems(lCol)
>>>>> If bSubTags Then
>>>>> ListViewRowGet = ListViewRowGet & sSep &
>>>>> LVW.ListItems(lRow).ListSubItems(lCol)
>>>>> .T ag
>>>>
>>>> Above I see...
>>>>
>>>> LVW.ListItems(lRow).SubItems(lCol)
>>>>
>>>> ....and also....
>>>>
>>>> LVW.ListItems(lRow).ListSubItems(lCol).Tag
>>>>
>>>>
>>>>
>>>> IIRC, .SubItems(lCol) is the Common Controls 5 version
>>>> hierarchy and .*List*SubItems(lCol) is the Common
>>>> Controls 6 callout.
>>>>
>>>> I'm guessing you are using v5 if the .SubItems(lCol)
>>>> line didn't error out.
>>>
>>> It is both VB6 and Common Controls 6. Both
>>> .SubItems(lCol) and .*List*SubItems(lCol) are accepted.
>>
>> I see that now.
>>
>> FWIW, I just created a test project populating a LV with
>> rows and columns using both .ListSubItems.Add, and using
>> .Subitem (x) = Text......
>>
>> ...and both ways, I could access the .tag property w/o
>> error, whether or not the tag was set to anyting.
>
> Strange. Did you not touch the SubItem?
> In my case I only touched the .Text, SubItem(1) and
> itmX.Tag (the row tag). DId not touch the SubItem(2) or
> ListSubItem(2).Tag.

In a new project, on a form I added a LV from CC ver6 (sp6),
set it to report view, and added 5 column headers.

The extent of the test code was:

Private Sub Command1_Click()

Dim x As Long

For x = 1 To 25
lv1.ListItems.Add , , "List-Item " & x
lv1.ListItems(x).SubItems(1) = "Sub-Item 1"
lv1.ListItems(x).SubItems(2) = "Sub-Item 2"
lv1.ListItems(x).SubItems(3) = "Sub-Item 3"
lv1.ListItems(x).SubItems(4) = "Sub-Item 4"
Next

End Sub

Private Sub Command2_Click()

If Not (lv1.SelectedItem Is Nothing) Then
lv1.SelectedItem.ListSubItems(2).Tag = Time$
Debug.Print "Item " & lv1.SelectedItem.Index & " tag
set to: " & Time$
End If

End Sub

Private Sub Command3_Click()

If Not (lv1.SelectedItem Is Nothing) Then
If Len(lv1.SelectedItem.ListSubItems(2).Tag) Then
Debug.Print "Item " & lv1.SelectedItem.Index & "
tag: " & lv1.SelectedItem.ListSubItems(2).Tag
Else
Debug.Print "Item " & lv1.SelectedItem.Index & "
has no tag"
End If
End If

End Sub

Button 1 to populate the LV.
Button 2 to set Sub-Item(2) tag of the selected item.
Button 3 to debug.print Sub-Item(2).tag of the selected item.