Set ComboBox SelectedValue

  • Thread starter Thread starter Rajesh Patel
  • Start date Start date
R

Rajesh Patel

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

Rajesh Patel
 
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.
 
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
 
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.
 
Thanks a lot, I think that'll work!

Mike

--


Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
 
Back
Top