By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

ComboBox Visual Basic 2005

P: 16
Hi I have a question about the Combo Box

This is the only Code I have seemed to be able to find to add items to a Combo Box... Is there a way to modify it or another command that I could use to have my own index or value inserted, but display the text NewField

Expand|Select|Wrap|Line Numbers
  1. Me.evSelectName.Items.Add("NewField")
So that when the click 'NewField' the value stored/read would equal something else?

Thanks in advance!
Sep 13 '07 #1
Share this Question
Share on Google+
2 Replies


kadghar
Expert 100+
P: 1,295
Hi I have a question about the Combo Box

This is the only Code I have seemed to be able to find to add items to a Combo Box... Is there a way to modify it or another command that I could use to have my own index or value inserted, but display the text NewField

Expand|Select|Wrap|Line Numbers
  1. Me.evSelectName.Items.Add("NewField")
So that when the click 'NewField' the value stored/read would equal something else?

Thanks in advance!
combobox1.list = Array
will add an array to your combo box

combobox1.additem ("newfield")
will add an item

if you want to know the index of the item you have selected use combobox1.listindex

lets say you want a msgbox that shows the item you've selected this could work:

msgbox combobox1.list(combobox1.listindex)

HTH
Sep 13 '07 #2

P: 16
Thanks, but I guess I haven't made myself to clear and after second read of my own question it did need a little clarification

I am trying to read the Combobox items from a Database

Expand|Select|Wrap|Line Numbers
  1.  
  2.         'Build Full Employee Data Set'
  3.         Dim sql As String
  4.         Dim empDS As New DataSet
  5.         Dim maxrows As Integer
  6.         Dim inc As Integer
  7.         con.Open()
  8.         sql = "SELECT FirstName, LastName FROM Employee_table"
  9.         da = New OleDb.OleDbDataAdapter(sql, con)
  10.         da.Fill(empDS, "Employees")
  11.         con.Close()
  12.         maxrows = empDS.Tables("Employees").Rows.Count
  13.         inc = 0
  14.         Do Until inc = maxrows
  15.             Me.evSelectName.Items.Add(empDS.Tables("Employees").Rows(inc).Item("LastName") & ", " & empDS.Tables("Employees").Rows(inc).Item("FirstName"))
  16.             inc = inc + 1
  17.         Loop
  18.  
  19.  
When I do this I want to set the employee ID as the value/selected index so that in another program I can pull the Employee ID.

Thanks!
Sep 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.