StrataFrame Forum

How do I retrieve the value from a combo box?

http://forum.strataframe.net/Topic9738.aspx

By Robert Carl Johnson - 6/22/2007

Hi all. I am a little confused regarding lists and combo box's I guess. I looked at the tutorial and but I don't see how you "get" the values from the selected record from the list or combo box. I have a combo box set up on my custom password form with two columns, FullName and ID: {0},{1} respectivly. Now, the value I need to retrieve is the ID value. I tried placing some code in the events SelectedIndexChanged with no joy. I'm not sure of the arguments to use to get my value. Can someone please help me. ID is an Integer.



The second part: What I'm trying to do is, after getting the ID number is send that number to my function and have the funtion run a select to get the employee record and return to me the password. I will then assign it to my var EmpPW as seen below. cboFullName is the name of the Combobox and I'm guessing at .ValueMember



Am I wrong or right? If incorrect then how do I do this?



My code to send to my Function is: EmpPW = Me.EmployeeBO1.GetEmpoyeeByID(txtFullName.ValueMember.



Thanks in advance



Robert

(New to .Net)
By Trent L. Taylor - 6/22/2007

If you are using the population data source settings on the control, then you specify the value member.  It might help if you just look into how a combo box natively works when using a DataSource as this is really all that we do behind the scenes.  We populate based on your PopulationDataSourceSettings property or Enumeration then create an ADO.NET data table that has two fields...Description and Value.  The description is what you see that is defined in the Display Member Format String field and the Value is set to the Value Member.

All Lists and Combos have a property called SelectedValue which gives you the "selected' value of the control.  Likewise if you want to get the display value you can just reference the Text property.

For example:

Dim lnValue As Integer = CType(MyCombo.SelectedValue, Integer)

or

Dim lcDisplayText As String = MyCombo.Text
By Robert Carl Johnson - 6/22/2007

Boy do I feel dumb. I didn't think to check normal behavior... I just figured it would be a SF property... lol. Well that teaches me a lesson.



Thanks for the reply Trent,



Regards,



Robert
By Greg McGuffey - 6/22/2007

Don't feel bad. I remember a bit O'head banging over this myself (among other simple things) BigGrin
By Trent L. Taylor - 6/22/2007

Boy do I feel dumb. I didn't think to check normal behavior.

Don't feel this way at all!!!  I am glad that you asked as at least you now know how it works.  If you don't ask you don't learn Smile  Please don't let this deter you from posting questions in the future!!! Smile