Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

ListView column widths off by 19 pixels...

Hello. I have an ActiveX control with an embedded ListView. These are the exported methods for getting/setting the ListView's column widths:

Public Property Get ListViewWidth (nColumn as Integer)
  Dim nCurrentScaleMode As Integer
  nCurrentScaleMode = ScaleMode
  ScaleMode = vbTwips
  ListViewWidth = ScaleX (lvListView.ColumnHeaders(nColumn).Width, vbTwips, vbPixels)
  ScaleMode = nCurrentScaleMode
End Property

Public Property Let ListViewWidth(nColumn As Integer, nWidth As Integer)
  Dim nCurrentScaleMode  As Integer
  nCurrentScaleMode = ScaleMode
  ScaleMode = vbTwips
  lvListView.ColumnHeaders(nColumn).Width = ScaleX (nWidth, vbPixels, vbTwips)
  ScaleMode = nCurrentScaleMode
End Property

The problem is that if I set the width of a column programmatically, the resulting column (on screen) is 19 pixels too large. For example, if I set a column width to 87 it comes out on the screen as 106. If I then get the column width using the above method, it reports it as 87. The really odd behavior is that if I use the mouse to drag a column to 106 pixels width and _then_ do a Get ListViewWidth, it reports it correctly as 106. So much for consistency...

I've tried setting the ScaleMode directly to vbPixels (without the ScaleX calls) and it behaves the same.

I'd greatly appreciate any light anyone could shed on this behavior, and how I might fix it!
0
mccluney
Asked:
mccluney
1 Solution
 
AzraSoundCommented:
Hello mccluney,
Just trying to make sense of the code here as it is all new to me. But why do you set the Scalemode to twips in setting the ListViewWidth when you are about to do a conversion from pixels to twips and you do the same for getting the ListViewWidth but when converting from twips to pixels instead??
0
 
caraf_gCommented:
Let me guess... you're using VB5, *or* you're using VB6 with the Microsoft Windows Common controls version 5....

If you're using the latter, you should be using Version 6.

Even if you're using VB5, you can actually use some VB6 controls. The Microsoft Windows Common Controls 6.0 are amongst those.
0
 
caraf_gCommented:
Sorry. An explanation.... It's a known bug with the VB5 version of the control. It's been fixed for the VB6 one.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Erick37Commented:
"FIX: Problem with ListView's ColumnHeader Width Property"

http://support.microsoft.com/support/kb/articles/Q179/9/88.ASP
0
 
mccluneyAuthor Commented:
The comments posted answered the question (thanks!) - but to reply to the questions asked:

I'm setting it to twips merely because that is the default for the control. It's unnecessary, and I'll probably put it back to pixels now that I know what's going on.

I'm using VB6, and I would have thought that I'm using the latest version of the control, but maybe I've installed something that stepped on it (or maybe the fix in VB6 isn't as effective as it should be). At any rate, the MS KB article gives a workaround, so I'm happy.
0
 
caraf_gCommented:
"I'm using VB6, and I would have thought that I'm using the latest version of the control"

That depends... If you've taken a project up from VB5, your project will be referencing the VB5 versions of the controls.

If you look at the project Components, you'll see that in the list of available components there are two entries for Microsoft Windows Common Controls: 5.0 and 6.0

If you are using 5.0 you're effectively still in "VB5" mode where your listview is concerned.

There are ways and means to upgrade to VB6. It's no big deal. Let me know if the above is the case for your project and if you're interested.
0
 
mccluneyAuthor Commented:
That hit the nail on the head. I am indeed interested in shifting it to use the VB6 components. If it is'nt already painfully clear, I'm somewhat new to VB programming (I'm a C++ guy who inherited a VB project) -- thanks for all your help!
0
 
caraf_gCommented:
No problem.

I'm afraid I might forget about this one, so please post another comment here. I'm at home at the moment and about to log off...

If you post another comment here, I'll have a fresh notification in the morning which will remind me to post the info here for you.

Pino
0
 
mccluneyAuthor Commented:
Thanks very much, but I was able to get it working (knowing that there was a problem was half the solution!) Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now