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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Component One VSflexgrid control

Status
Not open for further replies.

thomasks

Programmer
May 12, 2006
113
US
I am trying to develop an application that will open a database on a network drive then display the data from the table in a VSflexgrid control. And allow the user to edit the data and have it write back into the table on the network drive.
I am not really a programmer, just a technical user muddling through. But am learning as I go.
Are any of you familiar with using the Component One VSflexgrid control? Could you point me to an article or example code that does what I have described?
I appreciate your taking the time to educate me.
 
I used the flexgrid for many years. I really like their products.

If you go to their website they have a TON of example programs that you can download. There's also a couple that get installed with the app. What you're going to want to do is use ADO to connect to the database and populate the datagrid with a recordset. If you're trying to learn, then open their examples and step through them with F8. Then you can see how it works to add it to your app.
 
Ok, I tried to run the examples provided on the Component One web site and I get an error that it can't find the recordset Northwind. And that the provider was not defined.
Anyway, if I use ADO in the connection string, how to I point to the file name to open like T:\Quot\Estimating.mdb?
I tried to read the help on ADO but it is kind of vague on what each parameter in the string does. And the exact syntax to use. I know that these newbie questions can seem frustrating to you programming Gods, but how else you gonna learn but from mistakes?
Thanks in advance.
Any material that explains how to program the ADO connection and data manipulation would be helpful.
I had been using DAO but when I try to edit a record and update the changes it overwrites the first record that I opened. I think I have to somehow select the record to edit in the grid by the record ID.
 
ADO can do a lot for you. If you haven't already, I'd suggest you get a reference book to keep at your desk.

Now, to answer your question you can do it several ways. The easiest imo is to set up a System DSN on your workstation that points to the access database. Once you have that and you don't get an error when you click test datasource, you're ready to code against it.

First thing to do is add a reference to your project for Microsoft ActiveX Data objects 2.8. Then add the following code to your form where ever it needs to be


'Declare new connection and recordse
Dim cn as adodb.connection
Dim rs as adodb.recordset
dim str as string

'Instantiate connection
Set cn = new adodb.connection

'Configure connections connection string and open
cn.connectionstring = "DSN=MyDSN"
cn.open

'At this point you have an open connection to the database

'Instantiate recordset to access data
Set rs = new adodb.recordset

'Create query entry
str = "Select * from myTable where ID = 1000"

'pass query to recordset
'there's 2 entries after the connection entry that need
'to be set. I can't remember how they're formatted, but
'use intellisense to get them :)
rs.open str,cn,(1st),(2nd), adcmdText

'Recordset has information
If rs.eof = false then
rs.movefirst
Do until rs.eof = true
flexgrid.cell(0,0) = rs("data1")
flexgrid.cell(0,1) = rs("data2")
rs.movenext
Loop
End If
Set rs = nothing

cn.close


By the way, I realize I put a loop into a query that should only have one entry. I added that in to show how to loop through a recordset with more than one. You would need to add logic to keep up with the proper row number tho :) As it is, it would just keep overwriting the first row.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top