TheSwamp

Code Red => VB(A) => Topic started by: Keith™ on April 11, 2005, 05:08:29 PM

Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 05:08:29 PM
Ok, all of you API gurus .... (I hope there are some)

I want to mimic something the layer dialog does ... I want to place an icon image in the second and/or third column in a ListView control and have NO icon in the first column. Then I want the listview control to act independently on each "cell" as it were in the list. Click on column 2 and fire an event for the "selected" column, but don't fire an event for the first column or third column.

Any takers, or should I keep using my trial and error methods ...
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 05:31:26 PM
Look at the ReportIcon property.

e.g. Assuming ListView1 (report view) has an associated image collection with three 16x16 icons, with keys "icon0", "icon1" and "icon2" ...

Dim item As ListItem
Set item = ListView1.Add(, , "Field 0", , "icon0")
item.SubItems(1) = "Field 1"
item.ListSubItems.item(1).ReportIcon = "icon1"
item.SubItems(2) = "Field 2"
item.ListSubItems.item(2).ReportIcon = "icon2"

I'm drawing this from memory and did it blind so you may have to play with it a bit, but the basic info should be correct.
Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 06:24:26 PM
No go ...
According to MSDN ...
Quote

Returns or sets a value that specifies the image used for the ColumnHeader object when the View property is set to lvwReport
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 06:27:44 PM
Docs are wrong, I've done this Keith.
Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 06:35:11 PM
I just put the code in the form and it does not work ...
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 06:38:53 PM
Grrr ... I know I've done this.

I'll be you $50 I can add column specific icons without subclassing etc.

:cheesy:
Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 06:42:12 PM
Please show me ... because I have been trying my best to keep from subclassing ... you would think that the API would allow you to do it, but I have not found the right combination. I did find a bit of code, but it explicitly said it did not work with the SP3 release (6.0) and I need the 6.0 because I want the checkboxes for the listview.
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 06:45:30 PM
At home I'm running SP6 but at work (because I just changed PCs) I'm running the original Visual Studio 6 (no service pack). I'll see what I can do (already started it for you).
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 06:58:47 PM
Ok ... just a quick example.

This code (http://www.theswamp.org/lilly_pond/mp/files/ForKeith.zip?nossi=1) will produce this:

(http://www.theswamp.org/screens/mp/icons.png)

Edit: Added CheckBox toggle to code and simplified per next post.
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 07:08:58 PM
I just tried something else ...

if you replace the for loop in the example I provide with this:

Code: [Select]
       ...
        For i = 1 To 20
       
            Set item = .ListItems.Add(, , "Record" & Str(i))
            Call item.ListSubItems.Add(, , , "one")
            Call item.ListSubItems.Add(, , , "two")
            Call item.ListSubItems.Add(, , , "three")
           
        Next i
        ...

You'll find it works too.

Obviously in your working code you'll want to use indexes etc. (columnheader objects as well as listitems, and subitems) -- I didn't bother for this little exercise.
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 07:21:36 PM
And FYI ... (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/html/vbmthAddMethod(ListSubItemsCollection).asp)

Cheers.
Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 07:49:30 PM
Now, do you want to know something funny .... I used your code and it works just fine, BUT if I use the EXACT syntax with my ListView control, it does not work. The FRX indicates they are the exact controls... I guess I will paste yours into my form and use it ... go figure ...
I'll let you know when I get it fixed up ...
Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 08:07:41 PM
Ah ... I found the culprit ... an errant API call changing the extended ListView settings ... I edited the call and voila .. it now works fine ...
Thanks for being patient with me ...
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 08:50:37 PM
Quote from: Keith
Ah ... I found the culprit ... an errant API call changing the extended ListView settings ... I edited the call and voila .. it now works fine ...
Thanks for being patient with me ...

My pleasure, glad it's working for you.

Quote from: Keith
Then I want the listview control to act independently on each "cell" as it were in the list. Click on column 2 and fire an event for the "selected" column, but don't fire an event for the first column or third column.

You'll have to roll yer own code for this portion if I'm not mistaken. i.e. Use the ItemClick event to trap which ListItem was clicked, use the MouseDown or MouseUp event to trap the x coordinate of the mouse and compare against the widths of the ColumnHeaders to determine which SubItem actually took the hit. Hope that made sense.
Title: ListView Control (6.0)
Post by: Keith™ on April 11, 2005, 08:52:41 PM
I should be able to do that easily enough.
Title: ListView Control (6.0)
Post by: MP on April 11, 2005, 08:58:50 PM
An understatement; I expect you'll pen something quite elegant.
Title: Re: ListView Control (6.0)
Post by: MP on November 14, 2005, 11:34:07 AM
What ever came of this Keith, were you able to do what you wanted?
Title: Re: ListView Control (6.0)
Post by: Keith™ on November 14, 2005, 11:52:59 AM
Indeed ... thanks for asking ...
Title: Re: ListView Control (6.0)
Post by: MP on November 14, 2005, 11:54:03 AM
Good to hear.

Any generic code you can share with the rest of the class?

:)
Title: Re: ListView Control (6.0)
Post by: Keith™ on November 14, 2005, 12:04:57 PM
Not at this point, but if I get some time I will see if I can extract a bit and post it. This was for a client so I have to be very careful about dissemination of code.
Title: Re: ListView Control (6.0)
Post by: MP on November 14, 2005, 12:27:39 PM
Of course, I'd never ask you breach those boundaries.

I was just thinking about the code (or alternative technique) that corresponded to --

"You'll have to roll yer own code for this portion if I'm not mistaken. i.e. Use the ItemClick event to trap which ListItem was clicked, use the MouseDown or MouseUp event to trap the x coordinate of the mouse and compare against the widths of the ColumnHeaders to determine which SubItem actually took the hit."

Would prove interesting to see how you implemented it (or as noted, the alternative technique you may have used).

Of course, if that's what the client paid for then just ignore the inquiry.

Cheers.

:)
Title: Re: ListView Control (6.0)
Post by: Keith™ on November 14, 2005, 01:01:04 PM
What I finally did was a mouse down event with an x coordinate mask, then use the selected row to filter the actual item selected.