Solved

lock listview

Posted on 2009-03-31
5
716 Views
Last Modified: 2013-12-26
I need to be able to lock a ListView control.   In my app I want the user to be able to select an item from the ListView control.  When this happens a series of controls will populate with the properties of that item.  The user will have the option to edit those properties, but I don't want the user to be able to manipulate the ListView while editing is taking place.

If I disable the ListView,  the selection is lost.  Can't see which item is currently being edited and when you re-enable the ListView the selection is lost.

Any help ?
0
Comment
Question by:sidwelle
[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
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Antagony1960
ID: 24030697
If you set the ListView's "HideSelection" property to False the selected row will remain highlighted while the control is disabled.
0
 

Author Comment

by:sidwelle
ID: 24032922
That was simple enough.  Is there any way to change the colors so that you get the same colors if the control has focus or not ?

Thanks
0
 
LVL 11

Accepted Solution

by:
Antagony1960 earned 500 total points
ID: 24035044
I don't think so--nothing simple anyway. It may be possible to subclass the control to do it but that's beyond the scope of my expertise I'm afraid.

I know what you're getting at though: the grey highlighting color is pretty weak so it's difficult to see which item is being edited. Something I usually do is to emphasize the current selection by setting its font to bold in the ItemClick event (assuming it's text). If you're in Report view you can also bold the SubItems via the ListSubItems property. The attached code shows how to do that.

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Static iLastItem As Integer
Dim i As Integer
    With Item
        If .Index = iLastItem Then Exit Sub 'No Change/
        .Bold = True
        For i = 1 To .ListSubItems.Count
            .ListSubItems(i).Bold = True
        Next
    End With
    If iLastItem > 0 Then 'Reset the bolding on the deselected item/
        With ListView1.ListItems(iLastItem)
            .Bold = False
            For i = 1 To .ListSubItems.Count
                .ListSubItems(i).Bold = False
            Next
        End With
    End If
    iLastItem = Item.Index 'Record the current item number/
End Sub

Open in new window

0
 

Author Closing Comment

by:sidwelle
ID: 31564915
I didn't think it was going to be that simple. Thanks for the code. I do have an example that I worked out changing the background color via sub-classing.  Send me an Email if you want the code.
0
 
LVL 11

Expert Comment

by:Antagony1960
ID: 24050839
Glad to have helped. :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

730 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