Results 1 to 3 of 3

Thread: Keeping Selection on Listview when not in focus

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Lafayette, LA
    Posts
    14

    Question Keeping Selection on Listview when not in focus

    I'm told there is a way to keep the selection in a listview higlighted even though the listview no longer has focus with API calls? How may I do this. If there is a easier way without using API's that would be appreciated as well. Situation: I have a listview were I select a row and then have to fill out text boxes with specific data for that specific selection. However, when the listview loses focus you do not see the selection anymore (even though it is still selected). This is just a cosmetic thing...but I'd like to fix it.


    Thanks,
    Keith

  2. #2
    Tygur
    Guest
    Put this in the area above the rest of the code in the form: (the General Declarations area)
    Code:
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Const GWL_STYLE = (-16)
    Private Const LVS_SHOWSELALWAYS = &H8
    This is the code that will make the change you want in the ListView. I suggest that you put it in Form_Load:
    Code:
    Dim lStyle As Long
    lStyle = GetWindowLong(ListView1.hwnd, GWL_STYLE)
    lStyle = lStyle Or LVS_SHOWSELALWAYS
    SetWindowLong ListView1.hwnd, GWL_STYLE, lStyle
    Of course, you should replace whatever says ListView1 with the name of your ListView.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Lafayette, LA
    Posts
    14

    Smile Great...works...

    Is there a way to change the color of the selection? With this method it is Gray when I loose focus...can I change that? If so, which property/variable does that?

    Thanks for your time
    Keith

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width