Solved

ListView column widths off by 19 pixels...

Posted on 2000-03-31
9
455 Views
Last Modified: 2012-08-14
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
Comment
Question by:mccluney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2674528
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2674531
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2674534
Sorry. An explanation.... It's a known bug with the VB5 version of the control. It's been fixed for the VB6 one.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 32

Accepted Solution

by:
Erick37 earned 200 total points
ID: 2674611
"FIX: Problem with ListView's ColumnHeader Width Property"

http://support.microsoft.com/support/kb/articles/Q179/9/88.ASP
0
 

Author Comment

by:mccluney
ID: 2674677
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2675919
"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
 

Author Comment

by:mccluney
ID: 2681685
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2681789
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
 

Author Comment

by:mccluney
ID: 2691488
Thanks very much, but I was able to get it working (knowing that there was a problem was half the solution!) Thanks again!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question