DOCUMENT:Q193094 24-SEP-1998 [vbwin] TITLE :PRB: DataGrid or DbGrid May Not Display Data PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0,6.0 OPER/SYS:WINDOWS KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0 on the following platform: x86 --------------------------------------------------------------------- SYMPTOMS ======== After binding a DataGrid control to an ADO data control, you may not see any data displayed in the grid. This behavior occurs if you set or change any property of the Layout Property page of the DataGrid without executing the Retrieve Fields option of the DataGrid first. The same behavior is observed if using a DBGrid control. CAUSE ===== The data fields are not retrieved yet. RESOLUTION ========== The Layout Property page for either the DataGrid or the DBGrid controls contains properties available at design-time only and needs to be set after all fields are available or retrieved. To work around this problem, you need to run the Retrieve Fields method before setting any property on the Layout property page. STATUS ====== This behavior is by design. MORE INFORMATION ================ The following sample project uses a DataGrid control and a SQL Server database and also applies to the DBGrid. Steps to Reproduce Behavior --------------------------- 1. Create a Standard EXE project in Visual Basic. Form1 is created by default. 2. Add two components to the project, a Microsoft ADO Data Control 6.0 (OLEDB) and Microsoft DataGrid Control 6.0 (OLEDB). 3. Place both components on the default form and use their default names (ADODC1 and DataGrid1). 4. Right-click on the ADO data control and click on ADODC properties. On the General property page, use either ODBC Data Source Name or Connection String to connect to Pubs database. Set the RecordSource property page to use adCmdTable and Authors table. You may need to fill the Authentication property page with the proper UserName and Password. 5. Click on the DataGrid control and set the DataSource property to ADODC1. 6. Run the project and make sure that you see data in the grid. 7. Stop the project, right-click on the datagrid, click on Properties (or Custom property), and click on Layout tab. Set any property on the page (Locked, for example) and click OK. 8. Run the project again and observe that no data appears in the grid while the vertical scroll bar of the grid shows that it has some data. 9. Stop the project, right-click the datagrid control, click on the Retrieve Fields menu option, and then click on the "Yes" button in the message box. 10. The datagrid will be set back to the default Layout properties, so you need to reset any Layout Property changed in step 7. 11. Run the project and note that the grid filled again with data. (c) Microsoft Corporation 1998. All Rights Reserved. Contributions by Hussain Abuthuraya, Microsoft Corporation Additional query words: kbdse kbDSupport kbVBp kbCtrl kbDataBinding kbVBp500 kbVBp600 ====================================================================== Version : WINDOWS:5.0,6.0 Platform : WINDOWS Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.