Click to See Complete Forum and Search --> : ListView Problem...( ful row selection )


Abhijit B
March 11th, 1999, 02:40 PM
Hi Everybody,


The VisualBasic version is 5.0

My application has a ListView control.

I am doing a full row select by using SendMessage and the style as

LVS_EX_FULLROWSELECT, for which you need Comctl32.dll's new version

which comes with I.E 4.0. ( I have this new version ).

Now the problem is when I do F5 in VB, it runs properly i.e.

the full row is selected in the Listiew. But if I make an EXE

of that application, the full row selection doesn't take place.

Does anybody knows, why this happens.


Thanks

Abhijit

Chris Eastwood
March 11th, 1999, 05:03 PM
Hi


You need to call either the :


InitCommonControls


or


InitCommonControlsEx


API inside ComCtl32.dll.


Although this shouldn't matter (it should be initialised already), I've known it to cause problems on some PC's when InitCommonControlsXX has not been called.


Take a look at Randy Birch's example at :


http://www.mvps.org/vbnet/code/comctl/initcomctls.htm


Failing that - post your code here and I'll see if I can spot anything wrong.


Regards


Chris Eastwood


CodeGuru - the website for developers

http://www.codeguru.com/vb

Abhijit B
March 12th, 1999, 10:08 AM
Thanks for the Help, but it doesn't work.


Here's my code.

Module1 General - Declaration section


Option Explicit


Global itemHeight As Integer

Public Const ICC_LISTVIEW_CLASSES = &H1 'listview, header

Public Const LVM_FIRST = &H1000

Public Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 54

Public Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55

Public Const LVS_EX_FULLROWSELECT As Long = &H20

'For flat scrollbars

Public Const LVS_EX_FLATSB As Long = &H100


Type tagINITCOMMONCONTROLSEX ' icc

dwSize As Long ' size of this structure

dwICC As Long ' flags indicating which classes to be initialized.

End Type


'==========================================================

'Initializes the entire common control dynamic-link library.

'Exported by all versions of Comctl32.dll.

Declare Sub InitCommonControls Lib "comctl32.dll" ()


'Initializes specific common controls classes from the common

'control dynamic-link library.

'Returns TRUE (non-zero) if successful, or FALSE otherwise.

'Began being exported with Comctl32.dll version 4.7 (IE3.0 & later).

Declare Function InitCommonControlsEx Lib "comctl32.dll" _

(lpInitCtrls As tagINITCOMMONCONTROLSEX) As Boolean


'Declarations and constants to highlight a full row

'in the ListView control

Declare Function SendMessageAny Lib "user32" Alias "SendMessageA" _

(ByVal hwnd As Long, _

ByVal wMsg As Long, _

ByVal wParam As Long, _

lParam As Any) As Long


Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _

(ByVal hwnd As Long, _

ByVal wMsg As Long, _

ByVal wParam As Long, _

lParam As Long) As Long


Public Type LVBKIMAGE

ulFlags As Long ' Tiled or normal etc

hBitmap As Long ' Handle to the bitmap

pszImage As String 'File Name of bitmap

cchImageMax As Long ' Size of bitmap

xOffsetPercent As Long ' X Offset to display (if not tiled)

yOffsetPercent As Long ' Y Offset to display (if not tiled)

End Type


Public Const LVSIL_STATE As Long = 2

Public Const LVIF_STATE = &H8

Public Const LVIS_STATEIMAGEMASK As Long = &HF000

Public Const LVM_SETITEMSTATE = (LVM_FIRST + 43)

Public Const GWL_STYLE = (-16)

Public Const LVM_GETITEM = (LVM_FIRST + 5)

Public Const LVM_SETITEM = (LVM_FIRST + 6)

Public Const LVIF_INDENT = &H10&

Public Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38)

Public Const LVM_SETBKIMAGE = (LVM_FIRST + 68)

Public Const LVBKIF_SOURCE_URL = &H2

Public Const LVBKIF_SOURCE_HBITMAP = &H1

Public Const LVBKIF_STYLE_TILE = &H10

Public Const CLR_NONE = &HFFFFFFFF


Module1 General - InitComCtl32


'Common control Initializing routine.

'Returns True if the current working version of

'Comctl32.dll is available on the system and the

'new IE3 styles and messages can be used. Returns

'False either if the old version is present or

'Comctl32.dll isn't available at all. Also ensures

'that the library is loaded for use.

'We can get away with this hack rather than checking

'the file's version because VB resolves declared API

'function names only when they're called, not when 'it compiles the code...


Public Function InitComctl32(dwFlags As Long) As Boolean

Dim icc As tagINITCOMMONCONTROLSEX



On Error GoTo Err_OldVersion



icc.dwSize = Len(icc)

icc.dwICC = dwFlags



'VB will generate error 453 "Specified DLL

'function not found" here if the newer

'version isn't installed and the function's name

'can't be located in the library. The error is

'trapped and the generic API below is called instead.

InitComctl32 = InitCommonControlsEx(icc)

Exit Function

Err_OldVersion:

InitCommonControls

End Function

'=========================================================


Code in Form Load section

ASAP is my form name


Private Sub Form_Load()

Dim lStyle As Long

Dim tLVBKImage As LVBKIMAGE

Dim r As Boolean


'initialize the listview classes of the

'comctl32 dll by calling InitCommonControlsEx.

'If the dll does not support the class passed,

'the InitComctl32 routine's error is fired,

'and the InitCommonControls API is called.

r = InitComctl32(ICC_LISTVIEW_CLASSES)



ASAP.WindowState = vbMaximized



' Create an object variable for the ColumnHeader object.

Dim clmX As ColumnHeader

' Add ColumnHeaders. The width of the columns is the width

' of the control divided by the number of ColumnHeader objects.



Set clmX = ListView1.ColumnHeaders. _

Add(, , "xxxxxxxxxxx", ListView1.Width / 3)


Dim longStr, clmnHdrStr As String

Dim itemWidth, clmnHdrWidth As Integer



longStr = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"

itemWidth = TextWidth(longStr)

Set clmX = ListView1.ColumnHeaders. _

Add(, , "zzzzzzzzzzzzzzzzzzz", itemWidth)



longStr = "aaaaa"

itemWidth = TextWidth(longStr)

clmnHdrStr = "bbbbbbbbbb"

clmnHdrWidth = TextWidth(clmnHdrStr)

If itemWidth < clmnHdrWidth Then

itemWidth = clmnHdrWidth

End If



Set clmX = ListView1.ColumnHeaders. _

Add(, , "bbbbbbbbbb", itemWidth)



ListView1.View = lvwReport ' Set View property to Report.



itemHeight = TextHeight(longStr)



Dim listItem As listItem

'1.

Set listItem = ListView1.ListItems.Add(1, "a", "aaaaaaaaa")

listItem.SubItems(1) = "bbbbbbbbbbbbbbbbbb"

listItem.SubItems(2) = longStr

'2.

Set listItem = ListView1.ListItems.Add(2, "b", "cccccccccccccc")

listItem.SubItems(1) = "dddddddddddddddddddddddddddddddddd"

listItem.SubItems(2) = longStr

'3.

Set listItem = ListView1.ListItems.Add(3, "c", "eeeeeeeeeeeeeee")

listItem.SubItems(1) = "ffffffffffffffffffffffffffffffffffffffff"

listItem.SubItems(2) = longStr





With tLVBKImage

.ulFlags = LVBKIF_SOURCE_URL Or LVBKIF_STYLE_TILE

.pszImage = "D:\\TrialApplications\\Asap\\AAPISPLSHold.bmp"

.cchImageMax = Len(.pszImage)

End With


'

' Set the bitmap in the listview

'

SendMessageLong ListView1.hwnd, LVM_SETTEXTBKCOLOR, 0, ByVal CLR_NONE

SendMessageAny ListView1.hwnd, LVM_SETBKIMAGE, 0, tLVBKImage



'

' Set the full row selection

'

lStyle = SendMessageLong(ListView1.hwnd, _

LVM_GETEXTENDEDLISTVIEWSTYLE, _

0, 0)

lStyle = lStyle Or LVS_EX_FULLROWSELECT

'set the new listview style

SendMessageAny ListView1.hwnd, _

LVM_SETEXTENDEDLISTVIEWSTYLE, _

lStyle, 1



'The first item should be selected

ListView1.ListItems(1).Selected = True



End Sub


Thanks,

Abhijit

Chris Eastwood
March 12th, 1999, 10:24 AM
Hi


I haven't had a chance to check your code yet (will do later). For the time

being try the following code in a standalone exe:


1. Setup a Form with a listview in report view with a couple of column headings


2. In the Declarations Section :


Private Const LVM_FIRST As Long = &H1000

Private Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 54

Private Const LVS_EX_FULLROWSELECT As Long = &H20


Private 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


3. In your Form_Load event, add some items to the listview, then :


SendMessageLong ListView1.hwnd, _

LVM_SETEXTENDEDLISTVIEWSTYLE, _

LVS_EX_FULLROWSELECT, True


This is the new way of updating the Extended Styles in a listview in ComCtl version 4.71 or later.


Regards


Chris Eastwood


CodeGuru - the website for developers

http://www.codeguru.com/vb