Set ComboBox SelectedValue

R

Rajesh Patel

it should work. may be u can post some more code over here. what is the
style of cbolevel?

Rajesh Patel
 
M

Mike Caputo

Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I
know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--


Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
 
M

Mike Caputo

Rajesh Patel said:
it should work. may be u can post some more code over here. what is the
style of cbolevel?

Rajesh Patel

The style of cboLevel is DropDown. It's filled with business objects that
contain an ID field and a Description field. ID is the ValueMember and
Description is the DisplayMember. In this case, ID goes from 1 to 4, and I
am attempting to set the SelectedValue to 4.

cboLevel.SelectedValue = 4

Hmmmmm.... I just thought of something, not sure if this would affect the
ComboBox, but the ID field in the business object I'm using is ReadOnly. I
don't see why this would have any effect, but maybe that is the problem.
Any ideas?

Mike
 
I

IbrahimMalluf

Hello Mike


No, you can't do it that way.

Use the Description to set the level you want:


Me.cmbAccountUse.SelectedIndex =
Me.cmbAccountUse.FindString(MyUse.Item(Me._AccountUsesDataServices.enmAccoun
tUsesDataServices.Title))


In the code above, the cmbAccountUse combo is tied to the MyUse dataTable

The Item value is the Title of the use
The SelectedValue is the UseType Index

Use a FindString method to get the proper index of the SelectedValue you
desire.
 
M

Mike Caputo

Thanks a lot, I think that'll work!

Mike

--


Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top