Solved

Combo Box on VB form locks up application

Posted on 2013-01-28
7
1,037 Views
Last Modified: 2013-01-29
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_TrackingDataSet1.SignInOut' table. You can move, or remove it, as needed.
        Me.SignInOutTableAdapter.Fill(Me.Contractor_TrackingDataSet.SignInOut)
        lblHalt.Visible = False
        lblSignInComplete.Visible = False
        lblSignOutComplete.Visible = False
        btnOKClear.Visible = False


        'TODO: This line of code loads data into the 'Contractor_TrackingDataSet.SignInOut' table. You can move, or remove it, as needed.
        Me.SignInOutTableAdapter.Fill(Me.Contractor_TrackingDataSet.SignInOut)
        'TODO: This line of code loads data into the 'Contractor_TrackingDataSet.Company' table. You can move, or remove it, as needed.
        Me.CompanyTableAdapter.Fill(Me.Contractor_TrackingDataSet.Company)
        'TODO: This line of code loads data into the 'Contractor_TrackingDataSet.Person' table. You can move, or remove it, as needed.
        Me.PersonTableAdapter.Fill(Me.Contractor_TrackingDataSet.Person)
        'TODO: This line of code loads data into the 'Contractor_TrackingDataSet.Person' table. You can move, or remove it, as needed.

    End Sub

    Private Sub ddlContractorName_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub

End Class
*********************************************************************


Thanks!
0
Comment
Question by:jribble
  • 4
  • 2
7 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38828414
Hi ....for what you say this is a databound combobox..with display memer and Value Memeber...
what is your your Value Member ? what is your code to get the SelectedValue?
0
 

Author Comment

by:jribble
ID: 38828624
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.Person
VB-screenshot.docx
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38828678
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
Dim ddlContractorDrv as DataRowView=Ctype(ddlContractorName.SelectedItem,DatarowView)
Dim SelDate as Date=ddlContractorDrv.Item("Safety_Training_Date")
..
..
..

Open in new window

put this code in the Selected index event and set the SelDate where ever you want
Delete the selected value in the databind Mode.Also set the value member the "person_id"
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 38828845
DataSource=>PersonBindingSOurce
DisplayMember=>Fullname
ValueMember=>Person_id
SelectedValue=> None
This the Code
 Private Sub ddlContractorName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlContractorName.SelectedIndexChanged
        Try
            If ddlContractorName.SelectedIndex <> -1 Then

                Dim ddlContractorDrv As DataRowView = CType(Me.ddlContractorName.SelectedItem, DataRowView)
        Dim selDate As Date = CType(ddlContractorDrv.Item("Safety_Training_Date"),Date)
                Me.TextBox1.Text = selDate
            End If
        Catch ex As Exception

        End Try
    End Sub

Open in new window

Hope It Helps!!
0
 
LVL 27

Expert Comment

by:Ark
ID: 38829441
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_Name_Here")) or MsgBox(combo.SelectedItem(Column_Index_Here))
'Note - If option strict set ON then cast SelectedItem first:
MsgBox(CType(combo.SelectedItem,DataRowView)("Column_Name_Here"))
0
 

Author Closing Comment

by:jribble
ID: 38831617
Worked great!  I really appreciate that you posted the actual code.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38831731
Glad to help you
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get hold of longitude and latitude in iframe string 11 46
Gridview selected row 9 47
.NET 2008 VB and C# 6 28
VB.net Progress Bar - Maximum Value too large 2 12
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question