Solved

ListView column widths off by 19 pixels...

Posted on 2000-03-31
9
440 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
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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now