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

How to assign first list item to DataCombo at runtime

Status
Not open for further replies.

Sideman

Technical User
Apr 21, 2003
41
US
OK, here's another newbie question...
I use VB6, SP5, Access 2000.
I'm trying to assign, via code, the first list item in a DataCombo control so that at runtime the first item is selected automatically rather than having to click on a choice.. I've read many, many references to the DAO Combo box and it's ListIndex property, but haven't seen anything similar for the DataCombo using Adodc. Can this be done?
Please point me in the right direction.

P.S. I've searched the forums here, the FAQs, VB6 Help, and many books and can't seem to find a solution.

Of all the things I've lost, I miss my mind the most!
Sideman
 
paulbent, true...but there's no "ListIndex" property shown for a DataCombo box...just "Index" and it's for a different purpose I think.

Thanks

Of all the things I've lost, I miss my mind the most!
Sideman
 
Good point! I haven't used one of these controls but I think they have an editable text portion so try setting the Text property to the column value from the first row in the recordset.

Paul Bent
Northwind IT Systems
 
There is an editable text property - DataCombo.Text - which is where users would type the text that the DataCombo locates automatically for them (like in MS Help files). I want to select the first item through code at runtime as if the user clicked it.
Any code snippets to share along those lines??? I'll try anything once. :)

Thanks again.

Of all the things I've lost, I miss my mind the most!
Sideman
 
Um, all bound controls have an underlying recordset.

Therefore, in order to select an item in the DataCombo, or whatever, just select the item in the recordset.

You can either use:

rsADO.AbsolutePosition = 10

in order to select the 10th item

or use the rsADO.Find Method

If you use a data control, then just replace rsADO with Adodc1.Recordset, Adodc1 being the name of the datacontrol.

Because the bound control is indeed bound, and therefore the datacombo's current item followings the recordset's current record, or vica-versa, try to always use the underlying recordset's properties and methods to manipulate items in a bound control...it's much easier.
 
CClint,
Thanks for your reply. But, will setting the resordset's AbsolutePosition property change the DataCombo box selection? Maybe I'm missing something? Let me try to clarify the situation...
I'm using an Adodc with queries to create a recordset in the Adodc which I bind to the DataCombo box with the ListField property set to a column name when the form loads. This works fine. The query is changed via a variable according to user Option control choices which also changes the ListField property to show the new DataCombo listing. This also works fine.
Here's my problem...as you know the DataCombo box starts up with a blank Text field for user input. I'd like to "pre-select" the first item in the DataCombo box listing at runtime when the form is activated. This will immediately populate a DataGrid which displays specific data based on this DataCombo box selection. In other words, the first item in the DataCombo box is inserted into the DataCombo.Text field for the user right off the bat. Then the user can make other selections as desired.
I can't seem to figure out which DataCombo box property to use. With the older Combo box control there was the ListIndex property which allowed the selection of any item in the list simply setting the index number (ie.0 for the first item). Is there an equivalent for the DataCombo box?
I sure hope this explains things better...I've run out of ideas...maybe I can't do this at all...that's OK, I just need to know if I'm chasing my tail on this one.

Thanks for all you're help, CCLINT

Of all the things I've lost, I miss my mind the most!
Sideman
 
Oh, Oh, Oh, After putting this problem on the back burner, I returned to tackle it once more...Color me stupid...no wonder noone replied to my last post. You answered my question and I couldn't see it. (you know...the forest for the trees) I finally got it, duh!
Once again, thanks for putting up with our lack of knowledge. Your help is vital and very appreciated.

Of all the things I've lost, I miss my mind the most!
Sideman
 

>you know...the forest for the trees

Happens to all of us [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top