?
Solved

(Grid)Lines in a ListView /Report mode control ?

Posted on 1997-07-31
2
Medium Priority
?
287 Views
Last Modified: 2008-03-10
G'day again !

How to display rows & columns lines (separators) in a ListView in Report mode to make it looks like a grid, then I'll use this control, since it has many more useful events than the FlexGrid. (And a true PROPORTIONAL scroll bar thumb !)

I know it's possible to do it in a combo box, but I can't find back the infos, coz I figure out it's the same API call to perform this trick on a ListView control.

All my thanks in advance, dear Experts

Regards
0
Comment
Question by:Krosos
[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
2 Comments
 
LVL 3

Accepted Solution

by:
ESI earned 400 total points
ID: 1429176
By setting a ListView extended style bit using the API SendMessage with the message LVS_EX_GRIDLINES, the ListView columns and rows will be separated by a gray grid line.

Place the following API declare code into the general declarations area of a bas module:

Public Declare Function SendMessageLong Lib "user32" Alias  "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Const LVM_FIRST = &H1000
Const LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54)
Const LVM_GETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 55)

Const LVS_EX_FULLROWSELECT = &H20
Const LVS_EX_GRIDLINES = &H1

Then, once the list view populated, (or probably it works too on an empty listview), set the right bit :

    Dim rStyle As Long, r As Long
   
   'get the current ListView style  
    rStyle = SendMessageLong(ListView1.hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)

   'set the extended bit            
   rStyle = rStyle Or LVS_EX_GRIDLINES

   'or if u want remove the extended bit :
'   rStyle = rStyle Xor LVS_EX_GRIDLINES
   
   'set the new ListView style  
    r = SendMessageLong(ListView1.hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)

And U probably like the enable the system to highlight the entire row of a ListView (Looks far better)
The solution then is the message LVS_FULLROWSELECT :

Public Const LVS_EX_FULLROWSELECT = &H20
and perform the same operations as below (in fact, you can set the both bits at the same time indeed)
Above replace the line by

      rStyle = rStyle Or LVS_EX_GRIDLINES Or LVS_EX_FULLROWSELECT

that's all !

Well, have fun with our new improved ListView reports !
Bye
0
 

Author Comment

by:Krosos
ID: 1429177
Wow, thanks a lot ! it works fine. I give you 110 pts (no more, sorry)

Regards,
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

765 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