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

Combo Box List

P: n/a
I used the data form and data adapter wizards to build a data entry form.
However, rather than using text boxes for all of the fields, I would like to
use dropdown lists for some of the fields. What's the best way to populate
the selection list from a lookup table in my database.

Bob
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Robert,
I've something very similar to what you described here. So this is my
method:
1. Build your DataForm using the data form wizard as usual
2. Once it's done and working (make sure that it works because the dataforms
created using data form wizard not always work 100%), then add a ListBox (I
used a comboBox) to the DataForm for each of the text fields you want to
replace. Put the ListBox on top of the TextBox to hide it.
3. In your code, do this:
a. In the Sub LoadDataSet(), add this code

Public Sub LoadDataSet()
'Create a new dataset to hold the records returned from the call to
FillDataSet.
'A temporary dataset is used because filling the existing dataset
would
'require the databindings to be rebound.
Dim objDataSetTemp As Testing.myDs
objDataSetTemp = New Testing.myDs
Try
'Attempt to fill the temporary dataset.
Me.FillDataSet(objDataSetTemp)
Catch eFillDataSet As System.Exception
'Add your error handling code here.
Throw eFillDataSet
End Try
Try
'Empty the old records from the dataset.
objmyDs.Clear()
'Merge the records into the main dataset.
objmyDs.Merge(objDataSetTemp)
'
'Add this code.............. Replace the table name "Users" & the column
name "uDomain" to match your dataset
'
'Creates a copy of the dataset to load ComboBox1
Dim ds As DataSet = New DataSet
Dim i As Integer
ds = objmyDs
For i = 0 To ds.Tables("Users").Rows.Count - 1
ComboBox1.Items.Add(ds.Tables("Users").Rows(i).Ite m("uDomain"))
Next
'Done with dataset... Get rid of it
ds.Dispose()
ds = Nothing
'
'End of adding....................................
Catch eLoadMerge As System.Exception
'Add your error handling code here.
Throw eLoadMerge
End Try

End Sub

b. If you want the Items in ComboBox1 to change when you move between
records, add this code to your dataset_PositionChange() Sub.

Private Sub objmyDs_PositionChanged()
Me.lblNavLocation.Text = (((Me.BindingContext(objmyDs,
"Users").Position + 1).ToString + " of ") _
+ Me.BindingContext(objmyDs, "Users").Count.ToString)
'
'Add this code here *****************************
'
ComboBox1.SelectedItem =
ComboBox1.Items.Item(Me.BindingContext(objmyDs, "Users").Position)
ComboBox1.Refresh()
'
'*******************************************
End Sub

Hope this helps.
Stanav.

"Robert Boudra" <rb*****@comcast.net> wrote in message
news:uh****************@TK2MSFTNGP09.phx.gbl...
I used the data form and data adapter wizards to build a data entry form.
However, rather than using text boxes for all of the fields, I would like
to use dropdown lists for some of the fields. What's the best way to
populate the selection list from a lookup table in my database.

Bob

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.