ACC97: Listview Control Loses Data When Changing Properties (166912)
The information in this article applies to:
This article was previously published under Q166912
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you toggle the Visible or Enabled properties of a ListView control,
the control loses its records by approximately one-half each time that
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:
- Follow steps 1 through 7 in the "Steps to Reproduce Problem" section later in this article.
- 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.
REFERENCES
For more information about the ListView control, search the Help Index for
"ListView control."
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbbug kbinterop kbProgramming KB166912 |
---|
|