Solved

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

Posted on 1997-07-31
2
280 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
2 Comments
 
LVL 3

Accepted Solution

by:
ESI earned 100 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

776 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