BUG: DataGrid Doesn't Handle Special Filter Constants Correctly
ID: Q191919
|
The information in this article applies to:
-
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
-
ActiveX Data Objects (ADO), versions 1.5, 2.0, 2.1 SP2
SYMPTOMS
When the filter of an ADO recordset is set to one of the special constants,
such as adFilterPendingRecords, the bound DataGrid 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 will only show the rows that
are specific to that filter.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products
listed at the beginning of this article.
MORE INFORMATION
The code below that filters based on a field shows 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. The data grid, however, does not correctly display the
filtered recordset object.
Steps to Reproduce Behavior
- Create a Standard EXE Project in Visual Basic. Form1 is created by
default.
- From the Project/References menu, select Microsoft ActiveX Data Objects Library.
- From the Project/Components menu, select Microsoft DataGrid Control.
- Add a DataGrid Control, and two CommandButtons to Form1.
- Set the name and caption properties of the CommandButtons as follows:
Command1
Name = cmdFilterField
Caption = FilterField
Command2
Name = cmdFilterPending
Caption = FilterPending
- 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
- Press the F5 key to run the app and note behavior of the different
filter methods.
Additional query words:
Keywords : kbADO200bug kbCtrl kbDatabase kbVBp600bug kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2bug kbMDAC210SP2bug
Version : WINDOWS:1.5,2.0,2.1 SP2,5.0,6.0
Platform : WINDOWS
Issue type : kbbug