Lock a Listview while editing parent data

MyOwnBoss

Registered User.
Local time
Today, 00:23
Joined
Apr 30, 2009
Messages
12
Hi All,

I have a form that maintains data in a Parent Header Table while displaying data via a ListView from a Child Detail Table. The listview has various features such as Hover and a double-click event that opens a popup dialog form to edit its data.

While editing the parent, I would like to 1) Gray out or give a clear appearance that the listview is disabled when the user clicks the cmdEdit button. 2) Disable the click event. <Edit: I still want to display the rows.>

Pretty sure that it can not be done using built-in features of the listview, but what if I could put a transparent control over the listview so that it is still visible but in the back so it can not be clicked?

When finished editing the parent and the user clicks the cmdSave button, then the listview is restored of its functions.

My project is ADP, my form is UnBound using ADO connection to a SQL server.

Code:
Private Sub BuildEnrollList()
   On Error GoTo BuildEnrollList_Error

    With Me.lvwEnrollment
        
        'Set ListView style
        .View = lvwReport
        .LabelEdit = lvwManual

        .Width = 8999
        .HideSelection = False
        .GridLines = True
        .FullRowSelect = True
        
        'Clear Header and ListItems
        .ListItems.Clear
        .ColumnHeaders.Clear

    End With
    'Set up column headers
    With Me.lvwEnrollment.ColumnHeaders
        .Add , , " ", 0, lvwColumnLeft
        .Add , , "E-Date", 1075, lvwColumnLeft
        .Add , , "Program Number", 1450, lvwColumnLeft
        .Add , , "Program Type", 1190, lvwColumnLeft
        .Add , , "Counselor", 985, lvwColumnLeft
        .Add , , "Discharge", 1075, lvwColumnLeft
        .Add , , "Status Code", 3101, lvwColumnLeft
        .Add , , "Aord", 0, lvwColumnLeft
        .Add , , "ArchStatus", 0, lvwColumnRight
    End With

   On Error GoTo 0
   Exit Sub
   BuildEnrollList_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure BuildEnrollList of VBA Document Form_frmProfile"

End Sub
 
Sounds like you need to set the form that provides the ListView.Enabled = False. This will stop anyone accessing it until you reset the .Enabled = True.

The concept of placing a Text Box across the front of the ListView won't work directly as the Property BackStyle can only be Normal or Transparent. You will be able to hide the ListView but you will need to do something with it to enter new data into the ListView.

Found this piece of code which may help

With Forms("formname")
.Controls("controlname").InSelection = True
DoCmd.RunCommand acCmdSendToBack
.Controls("controlname").InSelection = False
End With

Good luck.
 
What you need to do is to set the BackColor property of the listbox to a suitable grey background to have the disabled effect. You can use something like vbButtonFace. You can then mimick a disabled interface by setting the Selected property of the Item to False. You do this in the ItemClick event, the Item argument is what you set to False:

Item.Selected = False

To enable it, do the reverse and allow Items to be selected.

If you've got a checkbox then you want to use the ItemCheck event and set the Ticked property accordingly.
 
I had to work on this for awhile but it works and gives me what I want

Code:
Private EditParentState As Integer
Private Sub Form_Open(Cancel As Integer)
    Call BuildEnrollList
    
    'Determinse that the listview is enabled
    Call EditParentData(0)


Code:
Private Sub cmdEdit_Click()
    
    Call EditParentData(1)
    ToggleEnable (True)
End Sub

Code:
Private Function EditParentData(ByVal toggleon As Integer) As Boolean

    If toggleon = 1 Then
        EditParentState = toggleon
        With lvwEnrollment
            .LabelEdit = lvwManual
            .ForeColor = 12632256
            .HideSelection = True
            .FullRowSelect = False
            .Appearance = ccFlat
        End With

    ElseIf toggleon = 0 Then
        EditParentState = toggleon

        With lvwEnrollment
            .View = lvwReport
            .LabelEdit = lvwManual
            .ForeColor = 0
            .HideSelection = True
            .FullRowSelect = True
        End With

    End If
End Function


'Double Click Event
Code:
Private Sub lvwEnrollment_DblClick()
   On Error GoTo lvwEnrollment_DblClick_Error
If EditParentState = 0 Then
   Call EditEnrollmentItem
Else
Exit Sub
End If
   On Error GoTo 0
   Exit Sub

lvwEnrollment_DblClick_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure lvwEnrollment_DblClick of VBA Document Form_frmProfile"
End Sub

'Lastly reverses the disable appearance and gives back it's funcations
Code:
Private cmdSave_Click()
ToggleEnable (False)
        Call EditParentData(0)
 

Users who are viewing this thread

Back
Top Bottom