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!

Automatically fill listview/datagrid with recordset results 2

Status
Not open for further replies.

rennis

Programmer
Dec 6, 2006
80
CA
Is there any way to automatically fill a listview or datagrid with the information retrieved from a ado recordset?

Basically, after the recordset.open " select......"

the information that this recordset retrieves, should automatically fill the listview or datagrid without specifying recordset!field1,recordset!field2 etc.

Any help would be appreciated
 
Do a search on 'bound controls'. You will see how to do it (and why you you shouldn't)

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
So basically for data integrity issues bound controls shouldn't be used? Thanks for your reply.
 
use filter show all data and
loop from record 0 to record count
listview.additem(adosample.re.field(name field).value
with this code


while not adosample.re.eof
listview.additem(adosample.re.field(name field).value
adosmple.recordset.movenext
wend

hope this help

 
oops sorry edited code

use filter show all data and
loop from record 0 to record count
listview.additem(adosample.re.field(name field).value
with this code


while not adosample.re.eof
listview.additem(adosample.recordset.field(name field).value
adosmple.recordset.movenext
wend

hope this help

 
>datagrid

Just set the DataSource to an ADODB Recordset.

You should either use a Disconnected recordset, or one created from scratch.

Under ADO, there is really nothing wrong or bad about using a DataGrid bound control, what data integrity and validation is concerned.
I guess the main drawback is not being able to format Cells independent from other cells (you can only format columns independent from other columns), and not being able to set individual cell/column colors and fonts.
I would however stay (far) away from using the DataControl.
 
Thanks everyone for your help.
bantakiah, I tried your method but i get a type mismatch error.

SBerthold,
Thanks for your reply

The reason i wanted to fill the listview automatically is because otherwise i would need to set up a case/loop to set each subitem individually
 
Finally got the error resolved. Just had to add a extra comma in as i had the text in the wrong position.

Also, would anyone know how to split a string based on a character? I've tried using the split function, but i cant seem to get it to work properly.
Basically if i had the string: 123,456,789, i would want to extract the first 3 charcters to the left of the first comma the first time through a loop, the second time through the loop, extract the second set of digits (456). etc.

Any help would be greatly appreciated.
 
This is basically an entirely different question and for the future, start a new thread for such.

The Split does work for this. Use a comma as the delimiter (optional argument of the split function)
 

Dim a as String()

a = Split(MyString,",")

a(0) = "123"
a(1) = "456
 
OK, Thank you SBerthold. I did have the split working correctly, but it didnt like that fact that i was trying to use it in the following fashion:
theQueryRecordSet!theOutArray(i).

Basically the array gets filled with fields from the table, and I need to output those values.
 

>Basically the array gets filled with fields from the table,

You mean Filed Values? The look at the recordset's GetRows method
 
No what i mean is that for my split array, value 1 will be the first field in the table. For instance, in the table there is f_name (first name) etc, so the first value in the array will be f_name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top