Question

I've got an old VB6 program that hasn't changed in a while but now has a new behavior. I'm thinking a common component was upgraded from underneath it. Here are the details.

I've got a standard ListView control in SmallIcon mode. Code snippet:

'setup the listview
With lvwMap
   .Appearance = ccFlat
   .BackColor = vbBlack
   .BorderStyle = ccNone
   .Font.Name = "Arial" 
   .Font.Bold = True
   .Font.Size = 9
   .ForeColor = vbYellow
   .LabelEdit = lvwManual
   .LabelWrap = True
   .OLEDropMode = ccOLEDropManual
   .PictureAlignment = lvwTopLeft
   .TextBackground = lvwOpaque
   .View = lvwSmallIcon
End With

Most ListItems that are added have both an SmallIcon and a Caption (Text). The TextBackground is set as Opaque, meaning the text is rendered in an enclosing colored rectangle.

Some items though may not have a caption provided or the user can change it such that there is no caption. This used to be fine, with just the SmallIcon showing. But now any ListItem that has an empty Text property renders a fairly wide enclosing rectangle with no text inside (as if a user keyed in a bunch of spaces perhaps).

The code to add a ListItem is straight-forward:

 Set oLI = lvwMap.ListItems.Add(lvwMap.ListItems.Count + 1, Key:=sKey)
 oLI.SmallIcon = sIcon
 oLI.Text = sCaption

I stopped the debugger here and thried the following in the immediate window:

oLI.Text= "AAAAAAA"
?oLI.Width
 100.0063 

oLI.Text= "AAAAAA"
?oLI.Width
 91.99371 

oLI.Text= "AAAAA"
?oLI.Width
 84.0189 

oLI.Text= "AAAA"
?oLI.Width
 76.0063 

oLI.Text= "AA"
?oLI.Width
 60.0189 

oLI.Text= "A"
?oLI.Width
 52.0063 

oLI.Text= ""
?oLI.Width
 96.00001 

As you can see the ListItem.Width correctly recalculates until the Text becomes empty and then jumps to 96 pixels.

Does anyone know any way to compensate for this behavior? Some windows message I can use to configure the default empty wdith? Any information on a change to ListView behavior might be helpful as well.

Was it helpful?

Solution

Mscomctl.ocx was updated in April to fix a security vulnerability in IE – and I'm guessing this is when its behaviour changed as I have a VM machine with an older version of the file (from 2004) that doesn't behave this way and I'm pretty sure that was the last release before the recent one.

As for what to do about it: well, I guess that depends on what it is about it that's causing you a problem. If it's because you're using the item's width property you could easily just multiply it with a Boolean evaluation, like this: iWidth = oLi.Width * Abs(oLi.Text <> ""). But if it's the appearance of it you don't like, the only thing I can think of is to mitigate the effect by adding a single space when/if the user sets it to empty. From a usage point of view the new behaviour is probably better if label editing is enabled, as it provides a wider area to click in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top