jribble
asked on
Combo Box on VB form locks up application
Here's the issue summary:
Developing in Visual Studio 2012 Pro using a VB.net form
SQL Server 2005 Enterprise backend.
I have a combobox (ddlContractorName) that is databound to a Contractor table. Its display member returns a string (Fullname), and the selected value returns a datetime associated with the Fullname for the record. This sits in a VB form inside a tab container. Once I click on the combobox it locks up my form. I can’t exit out, I can’t select any other controls via mouse or keyboard. I have to stop the program debugger to close it. This only happens if I populate the Selected Value portion of the combobox. If I set selected value to none, the form works perfectly. Only problem is that I need the value for calculations and logic.
I thought this might be caused from the datetime datatype not playing nicely, but it does the same thing when I use a string value for the selected value.
What the heck is causing this?
Here’s the relevant form source code:
************************** ********** ********** ********** ********** ***
Public Class frmHome
Private Sub FrmHome_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe t1.SignInO ut' table. You can move, or remove it, as needed.
Me.SignInOutTableAdapter.F ill(Me.Con tractor_Tr ackingData Set.SignIn Out)
lblHalt.Visible = False
lblSignInComplete.Visible = False
lblSignOutComplete.Visible = False
btnOKClear.Visible = False
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe t.SignInOu t' table. You can move, or remove it, as needed.
Me.SignInOutTableAdapter.F ill(Me.Con tractor_Tr ackingData Set.SignIn Out)
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe t.Company' table. You can move, or remove it, as needed.
Me.CompanyTableAdapter.Fil l(Me.Contr actor_Trac kingDataSe t.Company)
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe t.Person' table. You can move, or remove it, as needed.
Me.PersonTableAdapter.Fill (Me.Contra ctor_Track ingDataSet .Person)
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe t.Person' table. You can move, or remove it, as needed.
End Sub
Private Sub ddlContractorName_Selected IndexChang ed(sender As Object, e As EventArgs)
End Sub
End Class
************************** ********** ********** ********** ********** ***
Thanks!
Developing in Visual Studio 2012 Pro using a VB.net form
SQL Server 2005 Enterprise backend.
I have a combobox (ddlContractorName) that is databound to a Contractor table. Its display member returns a string (Fullname), and the selected value returns a datetime associated with the Fullname for the record. This sits in a VB form inside a tab container. Once I click on the combobox it locks up my form. I can’t exit out, I can’t select any other controls via mouse or keyboard. I have to stop the program debugger to close it. This only happens if I populate the Selected Value portion of the combobox. If I set selected value to none, the form works perfectly. Only problem is that I need the value for calculations and logic.
I thought this might be caused from the datetime datatype not playing nicely, but it does the same thing when I use a string value for the selected value.
What the heck is causing this?
Here’s the relevant form source code:
**************************
Public Class frmHome
Private Sub FrmHome_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe
Me.SignInOutTableAdapter.F
lblHalt.Visible = False
lblSignInComplete.Visible = False
lblSignOutComplete.Visible
btnOKClear.Visible = False
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe
Me.SignInOutTableAdapter.F
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe
Me.CompanyTableAdapter.Fil
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe
Me.PersonTableAdapter.Fill
'TODO: This line of code loads data into the 'Contractor_TrackingDataSe
End Sub
Private Sub ddlContractorName_Selected
End Sub
End Class
**************************
Thanks!
ASKER
I’m trying to do it through the GUI as opposed to coding it. Please see attached screenshot. The sql for the data source is just a “Select * From ContractorTracking.dbo.Per son
VB-screenshot.docx
VB-screenshot.docx
This is not the proper way....that is why the form freezes...you need as value the safety_training date after each selection ? if so try this
Delete the selected value in the databind Mode.Also set the value member the "person_id"
Dim ddlContractorDrv as DataRowView=Ctype(ddlContractorName.SelectedItem,DatarowView)
Dim SelDate as Date=ddlContractorDrv.Item("Safety_Training_Date")
..
..
..
put this code in the Selected index event and set the SelDate where ever you wantDelete the selected value in the databind Mode.Also set the value member the "person_id"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Safety_Training_Date should be NOT a "Selected Value" but "Value member" instead
Then, from code, you can access following combo properties:
combo.SelectedIndex - (almost) unbounded integer representing combo item index (though it's equal bindingsource.position)
combo.SelectedValue - equals Safety_Training_Date of selected item
combo.SelectedItem - DataRowView equals bindingsource.Current, you can access to table columns through it, like MsgBox(combo.SelectedItem( "Column_Na me_Here")) or MsgBox(combo.SelectedItem( Column_Ind ex_Here))
'Note - If option strict set ON then cast SelectedItem first:
MsgBox(CType(combo.Selecte dItem,Data RowView)(" Column_Nam e_Here"))
Then, from code, you can access following combo properties:
combo.SelectedIndex - (almost) unbounded integer representing combo item index (though it's equal bindingsource.position)
combo.SelectedValue - equals Safety_Training_Date of selected item
combo.SelectedItem - DataRowView equals bindingsource.Current, you can access to table columns through it, like MsgBox(combo.SelectedItem(
'Note - If option strict set ON then cast SelectedItem first:
MsgBox(CType(combo.Selecte
ASKER
Worked great! I really appreciate that you posted the actual code.
Glad to help you
what is your your Value Member ? what is your code to get the SelectedValue?