Solved

How to set SelectedItem in a DataBound Control?

Posted on 2000-05-05
8
1,165 Views
Last Modified: 2010-08-05
Hi,
I have multiple DataList & DataCombo controls.  I would like to be able to programmatically set which item in the DataList or DataCombo is selected as a default based on input from a textbox.  It seems like it should be a simple thing to do.  However, I can't figure out how to do it.  Any help would be greatly appreciated.
Thanks
 
 
0
Comment
Question by:lkath
8 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2780617
Use the SelectedItem property.

0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2780665
Nevermind.  I realized, too late, that you wanted to SET and not READ.
0
 

Author Comment

by:lkath
ID: 2780718
I thought that seemed the way to go.  However, I can't get it to work.  I have tried various variations such as:
  Set DataCombo1.SelectedItem = 3
or
  Set DataCombo1.SelectedItem.Text = adodcRS1.recordset!RS1Descpription

I've gotten errors with everything combination I have tried.

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 43

Expert Comment

by:TimCottee
ID: 2780759
You need to move to the appropriate record in the underlying recordset and then refresh the datacombo.

Private Sub Command1_Click()
    Adodc1.Recordset.Find "ProductName = '" & Text1.Text & "'"
    DataCombo1.Refresh
End Sub

This example sets the selected item of the datacombo1 to the value of the text1.text property. Where the datacombo is bound to the ADODC1 data control.

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2780770
Set adodcRS1.recordset.bookmark = DataCombo1.SelectedItem
0
 
LVL 3

Expert Comment

by:SirNick
ID: 2782326
Try

DataList.text = "the 1 u want"
0
 

Accepted Solution

by:
digimp earned 50 total points
ID: 2783981
after a datalist or a datacombo is linked to a database simply write

datacombo1= text1.text

0
 

Author Comment

by:lkath
ID: 2788284
Thank You All!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question