Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ListView column widths off by 19 pixels...

Posted on 2000-03-31
9
Medium Priority
?
465 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Accepted Solution

by:
Erick37 earned 800 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

730 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