How to loop data from Recordset into DataGrid
instead of setting the DataSource to the recordset, I would like to loop the data. I was previously used Sheridan Data Widgets (3rd party control) to populate and view data from a database and it was very easy using "DataGrid.AddItem" in DataGridView
May I know how do I do that using DataGrid?
Thank you in advance for any replies
Re: How to loop data from Recordset into DataGrid
I believe the DataGrid is a bound control, so I think you need to use the DataSource (I'm not completely sure as I've never used this control.)
Re: How to loop data from Recordset into DataGrid
Since DatGrid is a bound control you will have to loop through underlying recordset object.
In order for this code to work Adodc1.Recordset.CursorLocation must be set to adUseClient before your populate recordset.
Code:
Private Sub Command3_Click()
Dim i As Long
For i = 0 To Adodc1.Recordset.RecordCount - 1
'...
Next i
End Sub
Also, you mentioned the DataGridView name which is default name for a datagrid control in Visual Basic 2005; so, what version of VB do you actually use?
Re: How to loop data from Recordset into DataGrid
Actually the datagrid control that I normally use is SSDBGrid and not DataGridView. SSDBGrid is one of few controls from Sheridan. I am coding in VB6 by the way. Normally with SSDBGrid this is how I would do
Code:
str = "SELECT * FROM tblStkGrpCd"
Rst.Open str, POConn, adOpenKeyset, adLockOptimistic
With SSDBCStkGrpCd
.RemoveAll
Do While Not Rst.EOF
.AddItem Trim(Rst.Fields(0)) & vbTab & Trim(Rst.Fields(1))
Rst.MoveNext
Loop
End With
Rst.Close
Set Rst = Nothing
How do I do this part in standard VB6 DataGrid?
Code:
Do While Not Rst.EOF
.AddItem Trim(Rst.Fields(0)) & vbTab & Trim(Rst.Fields(1))
Rst.MoveNext
Loop
Re: How to loop data from Recordset into DataGrid
I would suggest consulting the SSDBGrid documentation
Re: How to loop data from Recordset into DataGrid
Quote:
How do I do this part in standard VB6 DataGrid?
You can't. The DataGrid does not support an "Unbound" mode. Use the MSFlexGrid or the MSHFlexGrid.
Re: How to loop data from Recordset into DataGrid
Quote:
Originally Posted by brucevde
You can't. The DataGrid does not support an "Unbound" mode. Use the MSFlexGrid or the MSHFlexGrid.
I guess that means there is no way for me to manually pump in data through coding?