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

Setting Drop DownList Selected ITem 1

Status
Not open for further replies.

checkai

Programmer
Jan 17, 2003
1,629
US
Here's what I do...on the right I have a drop down menu for each attribute of a JOB....on the right is a data list that is populated with current jobs...a user can copy the job on the right...(getting back jobTypeID)

So I have the jobtypeID in a variable for the copied item...

I want to set the drop down to show the text that relates to the ID in the drop down list...for instance...when I hit the copy button...jtype = 4...I want the drop down to show "Non Chargeable", i.e. where the value = 4....

Thanks,

DLC
 
Just to clarify:

You have a list of jobs, and a bunch of drop down lists that hold various attributes for a job.

When the user selects a job, you want the drop down lists to default to the attributes of the selected job.

Right?

If so, its actually pretty easy to do. In the event you have for selecting the job, have this code for each of the drop down lists:

DropDownList.ClearSelection()
DropDownList.Items.FindByValue(AttributeValue).Selected = True

Here's the breakdown:
Microsoft's documentation claims that the ClearSelection() isn't supposed to be used within the code we write (Only in the background by the framework). However, I've found it solved an issue I had coding something very similar to what you're trying to do (if you clear the selection, that means that you won't get the annoying "you can't have more than one item selected" error drop lists tend to throw).

The second line says "ok, for this drop down list, in the items collection, find the item with the value I'm searching for, and set the selected to True.

Voila!

Hope this helps, and if you need further clarification let me know.
:)

D'Arcy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top