Solved

lock listview

Posted on 2009-03-31
5
717 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

Technology Partners: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

717 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