Microsoft KB Archive/191803

= PRB: Click Event for DBGrid Returns Previous Row Values =

Article ID: 191803

Article Last Modified on 6/29/2004

-

APPLIES TO


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

-



This article was previously published under Q191803



SYMPTOMS
When clicking on a row of the DBGrid, the Click event is fired prior to the RowColChange event. If you attempt to print out the values of the columns collection in the Click event, the values from the previous row are printed.



RESOLUTION
To display data associated with the row you are navigating to, use either the Reposition event of the Data control (if the DBGrid is bound to the Data control) or the RowColChange event of the DBGrid control, or use the timer control in the Click event of the DBGrid.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Open a new Standard EXE project in Visual Basic. Form1 is created by default. Place a data control on the form and set these properties:

DatabaseName = Biblio.mdb

RecordSource = Titles Place a DBGrid the form. Set the DataSource property to Data1.  Enter the following code: Private Sub DBGrid1_Click Debug.Print DBGrid1.Columns(0).Value End Sub

 Press the F5 key to run and begin clicking on rows in the DBGrid. Note that the previous rows values are printed in the debug window.  Stop the project and enter the following code: Private Sub Data1_Reposition Debug.Print "Data1_Reposition Value=" & DBGrid1.Columns(0).Value End Sub

--OR-- Private Sub DBGrid1_RowColChange Debug.Print "DBGrid_RowColChange Value=" _ & DBGrid1.Columns(0).Value End Sub

--OR--

Add a Timer control to Form1 and add the following code: Private Sub DBGrid1_Click Timer1.Interval = 1 End Sub

Private Sub Timer1_Timer Debug.Print DBGrid1.Columns(0).Value Timer1.Interval = 0 End Sub

</li> Press the F5 key to run the project again and begin clicking on rows in the DBGrid. Note that one of the following will occur:

<ul> If the 1st or 2nd code option is used (Data1_Reposition or DBGrid1_RowColChange code segments), the user can capture the values from the row they are on, rather then the previous rows values.</li> If the timer control coding option was used (the 3rd coding option), the data for the currently selected row is printed to the debug window.</li></ul> </li></ol>

Additional query words: kbVBp400 kbVBp500 kbVBp600 kbdse kbDSupport kbVBp kbDebug

Keywords: kbprb KB191803

-

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

© Microsoft Corporation. All rights reserved.