Microsoft KB Archive/223064

= FIX: Filter Changes on DataSource Cause DataGrid to be Incorrect =

Article ID: 223064

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q223064



SYMPTOMS
Applying a Filter to an ADO Recordset bound to a DataGrid may result in the DataGrid showing incorrect rows or no rows at all, even if there are rows matching the Filter criteria.

This occurs if a row other than the first row is selected in the DataGrid before applying the new Filter to the ADO Recordset.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3.

For more information about Visual Studio 6.0 Service Packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



Steps to Reproduce Behavior
 Start Visual Basic 6.0. Choose to create a new Standard EXE project. Form1 is created by default.  Add the following Project References: Microsoft ActiveX Data Objects 2.0 Library   Add the following Project Components: Microsoft DataGrid Control 6.0 (OLEDB)   Add the following controls to Form1: <pre class="fixed_text">1 - Microsoft DataGrid Control 6.0 (OLEDB) 3 - Command Buttons </li>  Paste the following code into Form1's Code Window: Private rs As ADODB.Recordset

Private Sub Command1_Click 'Display the records that have '1' in Field1 rs.Filter = "Field1='1'" End Sub

Private Sub Command2_Click 'Display the records that have '2' in Field1 rs.Filter = "Field1='2'" End Sub

Private Sub Command3_Click 'Display the records that have '3' in Field1 rs.Filter = "Field1='3'" End Sub

Private Sub Form_Load Dim intField1 As Integer Dim i As Integer 'Create a new empty recordset with 3 fields Set rs = New ADODB.Recordset 'Allow 2 digits in each field (Field1 will be 1 to 10) rs.Fields.Append "Field1", adChar, 2 rs.Fields.Append "Field2", adChar, 2 rs.Fields.Append "Field3", adChar, 2 rs.Open 'Add 10 distinct rows. Field1 goes from 1 to 10. For intField1 = 1 To 10 'Add each distinct row 10 times: ' 10 rows with '1' in Field1, 10 rows with '2', etc.      For i = 1 To 10 rs.AddNew rs!Field1 = intField1 rs!Field2 = intField1 + 1 rs!Field3 = intField1 + 2 rs.Update Next i  Next intField1 'Populate the DataGrid Set DataGrid1.DataSource = rs End Sub </li> Run the project but do NOT click on the Grid.</li> Click each Command Button and note that the DataGrid correctly displays the rows from the Filtered recordset.</li> Click on a row in the DataGrid other than the first row.</li> Click each Command Button again and note that the DataGrid does not display any rows.</li></ol>

Keywords: kbbug kbfix kbdatabinding kbctrl kbvs600sp3fix KB223064

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.