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

DataList Control ( 2 fields in the ListField) 1

Status
Not open for further replies.

leaf

Programmer
Mar 9, 2000
32
0
0
US
I am trying to use the DataList control, I would like to display two fields from my database in the List. I can get one field to show but how do I display more than one field from my database.<br><br>
 
This is what I came up with for now!<br><br>First I run the Load_List() function in the Form Load. This will load the first and second fields from the Adodc1.<br>I load the key field from the table into the list1.ItemData so any time I select an Item from the list it then runs a do loop to move the adodc1 recordset to the record with the same key value.<br><br><br><br>-----------------------------------------------------<br>Function Load_List()<br>&nbsp;&nbsp;&nbsp;&nbsp;Adodc1.Recordset.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;Adodc1.Recordset.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;List1.Clear<br>&nbsp;&nbsp;&nbsp;&nbsp;Do While Not Adodc1.Recordset.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List1.AddItem Adodc1.Recordset(1) & &quot;.&quot; & Adodc1.Recordset(2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List1.ItemData(List1.NewIndex) = Adodc1.Recordset(0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Adodc1.Recordset.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Adodc1.Recordset.MoveFirst<br>End Function<br>----------------------------------------------------<br><br>Private Sub List1_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;On Error GoTo ErrorList1<br><br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Do While (List1.ItemData(List1.ListIndex) &lt;&gt; Adodc1.Recordset(0))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Adodc1.Recordset.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>ErrorList1:<br>Adodc1.Recordset.MoveFirst<br>&nbsp;&nbsp;&nbsp;&nbsp;Do While (List1.ItemData(List1.ListIndex) &lt;&gt; Adodc1.Recordset(0))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Adodc1.Recordset.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br><br>----------------------------------------------------<br><br>That's the best I can do for now, until I find a better solution. If anybody has any suggestions let me know.<br><br>p.s. Dont be a SUB be a Function!
 
Leaf,<br><br>Instead of that wee loop you *could* use the Recordset.FindFirst method.<br><br><FONT FACE=monospace><b><br>Adodc1.Recordset.MoveFirst<br>Adodc1.Recordset.FindFirst &quot;fld0 = &quot; & (List1.ItemData(List1.ListIndex) <br></font></b><br><br>Doesn't matter with small datasets but might make quite a difference with the larger ones. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top