Microsoft KB Archive/267745

= BUG: Hierarchical Flexgrid Row or Cell Selection Fails After Being Bound to an Empty Recordset =

Article ID: 267745

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q267745



SYMPTOMS
The Hierarchical Flexgrid control does not properly select rows or cells after it has been bound to an empty recordset and then rebound to a recordset that contains data. When you click a cell or a row, no row or cell is selected, or a row or cell that was not clicked is selected. When you use the EnterCell property of the grid to display the value in the cell you clicked, a value from a cell located above the cell you clicked displays instead.



RESOLUTION
To work around this problem, test for the condition of an empty recordset prior to binding a recordset to the Hierarchical Flexgrid control. If the recordset is empty, disable the grid and do not set the empty recordset to the Datasource property. Later, if a recordset is retrieved that does contain data, enable the grid and bind the control as usual.



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 same behavior occurs when you filter the recordset when it produces an empty recordset.

Steps to Reproduce Behavior
 Open a new Visual Basic Standard EXE project and set a reference to the Microsoft ActiveX Data Objects Library. Form1 is created by default. From the Project menu, click Components. In the Components dialog box, select the Microsoft Hierarchical Flexgrid component. Place an instance of the Hierarchical Flexgrid control onto Form1.  Copy and then paste the following code into Form1: Private Sub Form_Load Dim rs As ADODB.Recordset, cn As ADODB.Connection Set rs = New ADODB.Recordset Set cn = New ADODB.Connection ' Open a connection. cn.Open &quot;Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Program Files\Microsoft Visual Studio\VB98\nwind.mdb&quot; 'cn.Open &quot;DSN=NorthWind&quot; 'Using DSN to Nwind.mdb ' Open an empty recordset and bind it to the grid. rs.Open &quot;Select * from Employees where EmployeeId = 0&quot;, cn   Set MSHFlexGrid1.DataSource = rs    ' Now close the recordset and reopen it and bind it again to the grid. rs.Close rs.Open &quot;Select * from Employees&quot;, cn   Set MSHFlexGrid1.DataSource = rs End Sub

Private Sub MSHFlexGrid1_EnterCell Debug.Print MSHFlexGrid1.Text End Sub

NOTE: You might need to modify the connection string and query for this example to work properly. This example uses the sample Northwind database that is installed by default with Microsoft Access.

 Run the project, and try to click a cell in the grid. The cell is not properly selected, and either no cells are selected, or a random cell is selected instead. Also, note that the Debug window displays a value from a cell that is located above the clicked cell.

Additional query words: empty recordset

Keywords: kbbug kbpending KB267745

-

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

© Microsoft Corporation. All rights reserved.