The information in this article applies to:
SYMPTOMS
Moderate: Requires basic macro, coding, and interoperability skills.
When you toggle the Visible or Enabled properties of a ListView control,
the control loses its records by approximately one-half each time those
properties are cycled.
NOTE: This occurs with Microsoft ListView Control, version 5.0, which is
available with Microsoft Office 97 Developer Edition Tools.
RESOLUTION
Each time you toggle the Enabled or Visible properties of the ListView
control, clear the ListView control and rerun code to fill the control with
data. You can use the Clear method of the ListItems collection in the
control to remove all the items. The following example uses a command
button to toggle the Visible property of a ListView control without losing
rows of data:
- Perform steps 1 - 7 in the "Steps to Reproduce Problem" section below.
- Add a command button to the form. Set its Name property to Command0, and
set its OnClick property to the following event procedure:
Private Sub Command0_Click
Dim db As Database, rs As Recordset
Dim itmX As ListItem
Set db = CurrentDb()
Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
' Toggle the Visible property of the control.
Me!ListView1.Visible = Not Me!ListView1.Visible
' Clear and then refill the control with data.
While Not rs.EOF
Set itmX = ListView1.ListItems.Add(, , CStr(rs![FirstName] ))
If Not IsNull(rs![LastName]) Then
itmX.SubItems(1) = CStr(rs![LastName])
End If
If Not IsNull(rs![BirthDate]) Then
itmX.SubItems(2) = rs![BirthDate]
End If
rs.MoveNext
Wend
End Sub
- Save the form as frmListView, and then switch it to Form view. Note that
as you click the command button to toggle the Visible property of the
ListView control, the number of records displayed in the control remains
the same.
STATUS
Microsoft has confirmed this to be a problem in Microsoft Office 97
Developer Edition Tools. We are researching this problem and will post new
information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
The Microsoft ListView Control, version 5.0, is one of the controls
included in the ActiveX control file, Comctl32.ocx. This behavior exists
in version 5.00.3601 of Comctl32.ocx.
Steps to Reproduce Problem
- Start Microsoft Access and open the sample database Northwind.mdb.
- Create a new form not based on any table or query in Design view.
- On the Insert menu, click ActiveX Control.
- In the Insert ActiveX Control dialog box, select Microsoft ListView
Control, version 5.0, and then click OK.
- Set the following properties of the ListView control:
Name: ListView1
Width: 4"
Height: 2"
- On the View menu, click Code.
- Type the following procedure, which populates the ListView control with
data when you open the form:
Private Sub Form_Open(Cancel As Integer)
Dim db As Database, rs As Recordset
Dim itmX As ListItem
Set db = CurrentDb()
Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
ListView1.ColumnHeaders.Add, , "First Name", ListView1.Width/3
ListView1.ColumnHeaders.Add, , "Last Name", _
ListView1.Width/3, lvwColumnCenter
ListView1.ColumnHeaders.Add, , "Birthdate", _
ListView1.Width/3
ListView1.View = lvwReport
While Not rs.EOF
Set itmX = ListView1.ListItems.Add(, , CStr(rs![FirstName] ))
If Not IsNull(rs![LastName]) Then
itmX.SubItems(1) = CStr(rs![LastName])
End If
If Not IsNull(rs![BirthDate]) Then
itmX.SubItems(2) = rs![BirthDate]
End If
rs.MoveNext
Wend
End Sub
- Add a command button named Command0 to the form, and set its OnClick
property to the following event procedure:
Private Sub Command)_Click()
Me!ListView1.Enabled = Not Me!ListView1.Enabled
End Sub
- Save the form as frmListView, and then switch it to Form view. Note that
as you click the command button to toggle the Enabled property of the
ListView control, the number of records displayed in the control reduces
by about half. However, after the number of records is reduced to one,
the last record continues to display even if you continue to click the
command button.
REFERENCES
For more information about the ListView control, search the Help Index for
"ListView control."
|