?
Solved

lock listview

Posted on 2009-03-31
5
Medium Priority
?
718 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 2000 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

800 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