Author Topic: ListView Control (6.0)  (Read 4375 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« 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 ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #1 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.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« Reply #2 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
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #3 on: April 11, 2005, 06:27:44 PM »
Docs are wrong, I've done this Keith.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« Reply #4 on: April 11, 2005, 06:35:11 PM »
I just put the code in the form and it does not work ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #5 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:
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« Reply #6 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #7 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).
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #8 on: April 11, 2005, 06:58:47 PM »
Ok ... just a quick example.

This code will produce this:



Edit: Added CheckBox toggle to code and simplified per next post.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #9 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.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #10 on: April 11, 2005, 07:21:36 PM »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« Reply #11 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 ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« Reply #12 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 ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #13 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.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
ListView Control (6.0)
« Reply #14 on: April 11, 2005, 08:52:41 PM »
I should be able to do that easily enough.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
ListView Control (6.0)
« Reply #15 on: April 11, 2005, 08:58:50 PM »
An understatement; I expect you'll pen something quite elegant.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17498
Re: ListView Control (6.0)
« Reply #16 on: November 14, 2005, 11:34:07 AM »
What ever came of this Keith, were you able to do what you wanted?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Re: ListView Control (6.0)
« Reply #17 on: November 14, 2005, 11:52:59 AM »
Indeed ... thanks for asking ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
Re: ListView Control (6.0)
« Reply #18 on: November 14, 2005, 11:54:03 AM »
Good to hear.

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

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Re: ListView Control (6.0)
« Reply #19 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

MP

  • Seagull
  • Posts: 17498
Re: ListView Control (6.0)
« Reply #20 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.

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Re: ListView Control (6.0)
« Reply #21 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal