Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box fills incorrectly

Status
Not open for further replies.

TennesseeFox

Programmer
Jul 24, 2004
14
US
Ive searched the site and the closest thing i've found was 796-742024, but it doesnt fully explain the fix for the problem.

Ive got a form created by the dataform wizard thats connected to a main table.
I've got a few combo boxes that were added that are bound to another table. The drop down list has values for eye color. Ive been able to populate the drop down with the correct info from eye_color table. My problem is when I open the form the data fills the combo boxes, some of the data is correct. The other boxes fill with the first item in the drop down list. I hit the forward record button then back button and the info in the dropdown is corrected. It only happens on the load proceedure of the form and displays the first item in the list.

here is the code created when I inserted the combo box:
Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.objsubinf, "SubjectInfo.Eyes"))
Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objsubinf, "SubjectInfo.Eyes"))
Me.ComboBox1.DataSource = Me.objsubinf.Eye_Color_Tbl
Me.ComboBox1.DisplayMember = "Eye_Color"
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(160, 504)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
Me.ComboBox1.TabIndex = 15
Me.ComboBox1.ValueMember = "Eye_Color"
'

Does anyone have a fix for this? and why does this occur on a few combos and not the others on the same form(the aforementioned code is exactly the same, aside from the different tables)???


Thank you

Tennessee
 
you have two databindings, one to the text part and one to selectedvalue, the selectevalue one should be enough it will fill the text part by itself.

I don't know if this will solve your problem but its a start. If that doesn't work come back an we will try something else.



Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
ive just tried that. i only have the value binding, and i have 1 combo box that displays the first in the list. the others display the correct value. i even added a new first record and that is displayed. any ideas?

Also I believe you helped me out on passing the record number to a new form. It works, but theres a glitch. If im on record 24 of the main and click the button it shows record 1 of the child form but the record number shows 24. and if theres a child record present it wont go to it. Do I need to add the code to the parent or child form to say:
if this record exists goto it if it doesnt add a new record with that record number. Im having a bit of trouble with the syntax- i'm still trying to find the books on vb.net and how to write it properly

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
On Error GoTo Err_Button2_Click
Dim VehicleEntry As New VehicleEntry
Dim objVeh As DataSet
VehicleEntry.Show()
VehicleEntry.editRecordNumber.Text = Me.editRecordNumber.Text
If VehicleEntry.editRecordNumber.Text <> Me.editRecordNumber.Text Then VehicleEntry.BindingContext(objVeh, "Subject_Vehicle").AddNew()

Exit_Button2_Click:
Exit Sub

Err_Button2_Click:
MsgBox(Err.Description)
Resume Exit_Button2_Click

End Sub


Thanks again

 
the value that goes in the combobox that is showing the first in the list, is that Null or empty?

I recommend you read these articles and try not to use the wizard for making your datasets.



Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
ive tried it both ways. Ive tried the first was "contact" and just a blank entry. When the form loads the box has whatever is first in the source list either contact or just blank. I left the original text box on the form that shows whats in that field. The text box is correct but the list box shows a different value until i cycle to the next record and back. Is there a way to clear or reset the combobox prior to loading the form so it loads the comboboxes with the correct info and not the info from the source table????
 
If you built the form using the "data form wizard" then you do the following. This assumes you have one OleDbDataAdapter named OleDbDataAdapter1

1)Add a OleDbDataAdapter2 and configure it to grab the data from the appropriate table.

2) Generate a dataset by right clicking the OleDbDataAdapter2 you just configured.

3) Choose a table to add to the existing dataset (already built by form wizard)

4) Now you need to edit your code, every place you find coding for previous OleDbDataAdapter1 you must add an exact line for OleDbDataAdapter2.

HERE IS AN EXAMPLE IN MY FORM THERE WILL BE SEVERAL PLACES TO LOOK IN THE CODE.

Public Sub UpdateDataSource(ByVal ChangedRows As DublinFundRaisingProject.contact)
Try
'The data source only needs to be updated if there are changes pending.
If (Not (ChangedRows) Is Nothing) Then
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to update the data source.
OleDbDataAdapter1.Update(ChangedRows)
OleDbDataAdapter2.Update(ChangedRows)
End If
Catch updateException As System.Exception
'Add your error handling code here.
Throw updateException
Finally
'Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top