BUG: DataGrid Does Not Handle Special Filter Constants Correctly (191919)



The information in this article applies to:

  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP4
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP5
  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1 SP2
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7

This article was previously published under Q191919

SYMPTOMS

When the filter of an ADO Recordset object is set to one of the special constants, such as adFilterPendingRecords, the bound DataGrid control still displays all of the rows in the Recordset. If the filter is set to specify a particular field, such as "State = 'CA'," the DataGrid displays only the rows that are specific to that filter.

STATUS

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

MORE INFORMATION

The code that follows filters based on a field and displays the appropriate data in the grid.

Modifying records in the data grid and setting the Filter property of the Recordset to display only records with pending changes (Filter = adFilterPendingRecords) causes the recordset to correctly filter on those changed records. However, the DataGrid does not correctly display the filtered Recordset object.

Steps to Reproduce the Behavior

  1. Create a Standard EXE project in Visual Basic. Form1 is created by default.
  2. On the Project menu, click References.
  3. In the list of available references, click Microsoft ActiveX Data Objects Library.
  4. On the Project menu, click Components.
  5. In the list of available components, click Microsoft DataGrid Control 6.0 (OLEDB).
  6. Add a DataGrid control and two CommandButton controls to Form1.
  7. Set the name and the caption properties of the CommandButton controls as follows:
    • Command1:
      Name = cmdFilterField
      Caption = FilterField
    • Command2:
      Name = cmdFilterPending
      Caption = FilterPending
  8. Add the following code to the General Declarations of Form1:
          Dim rsAuthors As New ADODB.Recordset
          Private Sub cmdFilterField_Click()
            rsAuthors.Filter = adFilterNone
            rsAuthors.Filter = "State = 'UT'"
          End Sub
    
          Private Sub cmdFilterPending_Click()
            rsAuthors.Filter = adFilterNone
            rsAuthors.Filter = adFilterPendingRecords
          End Sub
    
          Private Sub Form_Load()
            Dim cnPubs As New ADODB.Connection
            Dim strConn As String
    
            ' You may have to change the following line
            ' to a valid SQL Server
            strConn = "Provider=SQLOLEDB;Data Source=(local);" & _
                     "Initial Catalog=pubs;"
    
            cnPubs.CursorLocation = adUseClient
            cnPubs.Open strConn, "sa", ""
    
            rsAuthors.Open "SELECT * FROM Authors", cnPubs, adOpenStatic, _
                      adLockBatchOptimistic
    
            Set rsAuthors.ActiveConnection = Nothing
    
            cnPubs.Close
    
            Set DataGrid1.DataSource = rsAuthors
    
          End Sub
    					
  9. Press the F5 key to run the application, and note the behavior of the different filter methods.

Modification Type:MinorLast Reviewed:3/2/2005
Keywords:kbBug kbCtrl kbDatabase kbpending KB191919