Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate a datgrid dynamically

Status
Not open for further replies.

tornadoproggie

Programmer
Jul 11, 2002
6
0
0
US
Hi,

I am trying to modify a VB code where I need to populate a datagrid at runtime frm a ADODB recordset, which I am calling on form load, is this possible?
 
Try VBHelp. Look in Index for ADO. There are lots of references and some good samples to get you started.

You could also do a search in this forum for ADO and Datagrid. There have been several threads on the subjetc recently

See also FAQ referred below Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Yes its possible. Basically you need to loop through the recordset and populate the grid. Using a recordset I believe you will need to change rows for each record and manually place the fields into the cells.

Johnwm is correct, there are good examples you just need to do some searching. Thanks and Good Luck!

zemp
 
What I think zemp[b is referring to is the Flex Grid, which most seem to be using here. You have mentioned the use of the DataGrid.

You can have the FlexHGrid load automatically (It just will not be bound afterwards - good! most will say)
The MSHFlexGrid (OLEDB only) has a recordset property and a Datasource property which can be used to automatically fill the grid with data. (Set MSHFlexGrid1.Recordset = rsADO)

But, best is probably like zemp has mentioned if you have (or may have someday) alot of records. Then you can control how many records actually get loaded if you want, in order to speed things up, and then fetch more records as you go along.

Another advantage of using the FlexHGrid is that you can fill the grid with data in one line of code using a Server Side cursor. A DataGrid needs a Client side cursor.
And, with the MSHFlex you can create Bands.

Using the DataGrid has also it's advantages. You can load the data from a recordset that has been opened with using the adAsyncFetch method. You can also edit data directly in the DataGrid, affection the fields in the underlying recordset directly (bound in other words, but using a disconnected recordset will give that control back) The lack of formating cells and rows with different colors are one of the dis-advantages.


>populate a datagrid at runtime frm a ADODB recordset

Build the recordset, using a client side cursor for a DataGrid, and just add:

Set DataGrid1.DataSource = rsMyRecordset
[/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Yes I was referring to the MSFlexGrid. Sorry for the confusion.

Thank you CCLINT for catching that and clarifying it. Thanks and Good Luck!

zemp
 

No problem. Do the same for me where needed!

That Bold mistake of mine [ponder] makes it hard to read.... [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top