Replaced textboxes with comboboxes - now I get "An unhandled exception of type 'System.StackOverflowException' occurred in *****.exe"

TSFLLC
TSFLLC used Ask the Experts™
on
I have a Windows form that previously contained custom AutoComplete functionality and was tied to about 15 textboxes.  I just finished stripping those textboxes and replacing them with standard unbound comboboxes with AutoComplete turned on.

EVERY time I open the form, access a record or two.  THEN I close and reopen the form.  WHEN I POPULATE EITHER THE FIRST OR SECOND RECORD AGAIN....StackOverflowException.  Until I replaced textboxes with comboboxes, this form has worked for three years.

I don't ever use comboboxes.  So there are several things to note that I may or may not be doing correctly when using VB's combobox.  

1)  With my original autocomplete, I never performed a cmbobox.DataSource = dv, combobox.DisplayMember = "id", cmbobox.ValueMember = "desc" etc. until the textbox was active. Also, my autocomplete used a listbox instead of a combobox.  Now, I create With combobox.DataSource etc. for ALL of these comboboxes on FormLoad.  Is this appropriate or should I do this individually only when each combobox is accessed?

2)  When I populate the form using a dataview I populate the comboboxes with the .SelectedValue and not .Text.  It eleviates having to join all of these tables to my main table in a SQL select.  Is this inappropriate?  Should I set .Text?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
We need to see some code. Does it throw the exception on a specific line? You may have to step through the code to find out.

Author

Commented:
No it's random.

I'm about to modify my PopulateFields sub where I'm populating with cmbobox.SelectedValue and switch to cmbobox.Text as a test

Have you ever seen an issue with this?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Your question is like "my car's engine turns off randomly occasionaly. What could be the problem?". There is no specific answer to this question other than "something may be wrong with the engine"!
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
Please don't take offense to this, but let me put some things into perspective.

Many of us users would spend countless hours beating our heads against the desk attempting to resolve issues we have never been exposed to were it not for people like yourself devoting time to help us on Experts Exchange.  And I realize that Guru's, Master's, Sage's, etc. don't know everything about VB, but you're level of experience/exposure WAY outways many of ours.

On your profile....
>> I have been programming for about 10 years. I have worked with .NET since version 1 and all the versions of Visual Studio.
>> 04/03/2011: 5 million points in VB.NET

This, in my mind, gives me full expectancy....actually HOPE....that if there is a general issue with or it is programmatically inappropriate in VB.NET to "populating a combobox value using .SelectedValue instead of .Text" you would know.

You've actually solved a # of my issues yourself.  And I appreciate ALL of your help.

So this wasn't the reply I was expecting..... :)
Most Valuable Expert 2012
Top Expert 2014

Commented:
I understand what you are saying but I gave the engine analogy to say that it could be anything. There are many many ways of doing the same thing in programming world so I can not say what's wrong with your code unless I see the code.

>that if there is a general issue with or it is programmatically inappropriate in VB.NET to "populating a combobox value using .SelectedValue instead of .Text" you would know.

Now are you populating from a SQL Server database? Access database? XML file? List of Strings? populating using a datareader? using a datatable? using a LINQ query? Do you get my point?

Author

Commented:
I understand.

Included is my Form_Load, BuildTablesAndViews, PopulateFields & the stored procedure for use in PopulateFields.

I have already changed the cmbo**.SelectedValue to .Text

I also just tested it 5-6 times......  AND I DO NOT HAVE THIS PROBLEM ANYMORE.
I put them back in as .SelectedValue and the issue came back.
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtAssnCompany.Text = glCompanyName
        HelpPro.HelpNamespace = GetHelpFile()
        Me.Cursor = Cursors.WaitCursor
        ReActivateContactEntryForm = New dlgReActivateContactEntryForm(AddressOf xActivateContactEntryForm)
        RefreshCorrespondenceGrid = New dlgRefreshCorrespondenceGrid(AddressOf xRefreshCorrespondenceGrid)
        RefreshAccountingGrid = New dlgRefreshAccountingGrid(AddressOf xRefreshAccountingGrid)
        RefreshTable = New dlgRefreshTable(AddressOf xRefreshTable)
        RefreshACHBankTable = New dlgRefreshACHBankTable(AddressOf GetACHBanks)
        RefreshACHBankABANumTable = New dlgRefreshACHBankABANumTable(AddressOf xRefreshACHBankABANumTable)
        glIsClosing = False
        Activating = True
        MemberTab1.DrawMode = TabDrawMode.OwnerDrawFixed
        BuildTablesAndViews()
        glContactLevels = GetUserRights("contact")
        glACHLevels = GetUserRights("ACH").Substring(0, 1)
        Select Case glContactLevels
            Case "TTFTT"      'Supervisor Rights
                glContactSuper = True
                glContactReadOnly = False
                glContactReadWrite = True
                glContactDelete = True
            Case "TFFTT"      'Read-Write w/Delete
                glContactSuper = False
                glContactReadOnly = False
                glContactReadWrite = True
                glContactDelete = True
            Case "TFFTF"      'Read-Write no/Delete
                glContactSuper = False
                glContactReadOnly = False
                glContactReadWrite = True
                glContactDelete = False
            Case "TFTFF"      'Read-Only
                glContactSuper = False
                glContactReadOnly = True
                glContactReadWrite = False
                glContactDelete = False
            Case "TFTFT"      'Read/Delete Only
                glContactSuper = False
                glContactReadOnly = True
                glContactReadWrite = False
                glContactDelete = True
            Case "TFFFT"      'Delete Only
                glContactSuper = False
                glContactReadOnly = False
                glContactReadWrite = False
                glContactDelete = True
            Case "FFFFF"      'No Access
                glContactSuper = False
                glContactReadOnly = False
                glContactReadWrite = False
                glContactDelete = False
        End Select

        glInvoicingLevels = GetUserRights("invoicing")
        Select Case glInvoicingLevels
            Case "TTFTT", "TFFTT"        'Supervisor Rights, Read-Write w/Delete
                glInvoicingGranted = True
                glInvoicingDelete = True
            Case "TFFTF", "TFTFF"      'Read-Write no/Delete, Read-Only
                glInvoicingGranted = True
                glInvoicingDelete = False
            Case "FFFFF"    'No Access
                glInvoicingGranted = False
                glInvoicingDelete = False
        End Select
        glCorrespondenceLevels = GetUserRights("correspondence")
        Select Case glCorrespondenceLevels
            Case "TTFTT", "TFFTT"        'Supervisor Rights, Read-Write w/Delete
                glCorrespondenceGranted = True
                glCorrespondenceDelete = True
            Case "TFFTF", "TFTFF"      'Read-Write no/Delete, Read-Only
                glCorrespondenceGranted = True
                glCorrespondenceDelete = False
            Case "FFFFF"    'No Access
                glCorrespondenceGranted = False
                glCorrespondenceDelete = False
        End Select
        glACHLevels = GetUserRights("ACH")
        Select Case glACHLevels
            Case "TTFTT", "TFFTT"        'Supervisor Rights, Read-Write w/Delete
                glACHGranted = True
            Case "TFFTF", "TFTFF"      'Read-Write no/Delete, Read-Only
                glACHGranted = True
            Case "FFFFF"    'No Access
                glACHGranted = False
        End Select

        Activating = True
        CheckContacts()
        If glNewContact Then
            ClearFields()
        Else
            ClearFields()
            Activating = True
            If myFormsList.ContainsKey(90) And Misc_SearchRecs.Instance.glContactFromSearch Then
                glContactID = Misc_SearchRecs.Instance.glSearchContact
            End If
            PopulateFields()
        End If
        Cursor.Current = Cursors.Arrow
        Activating = False
    End Sub
    Sub BuildTablesAndViews()
        Try
            GetUserTableSortOrderValues()
            dtRecruitedBy = GetRecruitedByAscNameDS.Tables("contact")
            dvRecruitedBy.Table = dtRecruitedBy
            dtContactType = GetTblByOrderDS("tbl_contact_type").Tables("tbl_contact_type")
            dvContactType.Table = dtContactType
            dtCounty = GetCountyDS.Tables("tbl_county")
            dvCounty.Table = dtCounty
            dtSchoolDistrict = GetTblByDescriptionDS("tbl_school_district").Tables("tbl_school_district")
            dvSchoolDistrict.Table = dtSchoolDistrict
            dtMemberCategory = GetTblByDescriptionDS("tbl_member_category").Tables("tbl_member_category")
            dvMemberCategory.Table = dtMemberCategory
            dtBuildingRep = GetTblByOrderDS("tbl_yesno").Tables("tbl_yesno")
            dvBuildingRep.Table = dtBuildingRep
            dtRecruiterType = GetTblByOrderDS("tbl_recruiter_type").Tables("tbl_recruiter_type")
            dvRecruiterType.Table = dtRecruiterType
            GetAreaDirector()
            dtMemberActiveStatus = GetTblByOrderDS("tbl_member_active_status").Tables("tbl_member_active_status")
            dvMemberActiveStatus.Table = dtMemberActiveStatus
            dvMemberActiveStatus.RowFilter = "field_order <> 4"
            dtSalutation = GetTblByOrderDS("tbl_salutation").Tables("tbl_salutation")
            dvSalutation.Table = dtSalutation
            dtCSalutation1 = GetTblByOrderDS("tbl_salutation").Tables("tbl_salutation")
            dvCSalutation1.Table = dtCSalutation1
            dtCSalutation2 = GetTblByOrderDS("tbl_salutation").Tables("tbl_salutation")
            dvCSalutation2.Table = dtCSalutation2
            dtAssessmentCategory = GetAssessmentCategoryDS(glCompany, 2).Tables("tbl_assessment_category")
            dvAssessmentCategory.Table = dtAssessmentCategory
            dtRecordEntryType = GetTblByOrderDS("tbl_record_entry_type").Tables("tbl_record_entry_type")
            dvRecordEntryType.Table = dtRecordEntryType
            dtPaymentTerm = GetPaymentTermDS.Tables("tbl_payment_term")
            dvPaymentTerm.Table = dtPaymentTerm

            dtYesNo = GetTblByOrderDS("tbl_yesno").Tables("tbl_yesno")
            dvCorporateYesNo.Table = dtYesNo
            GetCorporateIndexDS()
            GetACHBanks()
            GetACHBankABAs()
            GetACHTransactionCodes()

            With cmboContactID
                .DataSource = dvGlobalContactID
                .ValueMember = "contact_id"
                .DisplayMember = "contact_id"
            End With
            With cmboContactIndex
                .DataSource = dvGlobalContactIndexes
                .ValueMember = "contact_id"
                .DisplayMember = "contact_index"
            End With
            With cmboContactType
                .DataSource = dvContactType
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboSalutation
                .DataSource = dvSalutation
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboDuesCategory
                .DataSource = dvAssessmentCategory
                .ValueMember = "assessment_category_id"
                .DisplayMember = "assessment_category_description"
            End With
            With cmboPaymentTerms
                .DataSource = dvPaymentTerm
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboStatus
                .DataSource = dvMemberActiveStatus
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboRecordEntryType
                .DataSource = dvRecordEntryType
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboCounty
                .DataSource = dvCounty
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboSchoolDistrict
                .DataSource = dvSchoolDistrict
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboMemberCategory
                .DataSource = dvMemberCategory
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboBuildingRep
                .DataSource = dvBuildingRep
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboRecruiterType
                .DataSource = dvRecruiterType
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboRecruitedBy
                .DataSource = dvRecruitedBy
                .ValueMember = "contact_id"
                .DisplayMember = "recruited_by_name"
            End With
            With cmboAreaDirector
                .DataSource = dvAreaDirector
                .ValueMember = "area_director_id"
                .DisplayMember = "asc_name"
            End With
            With cmboCorporateYesNo
                .DataSource = dvCorporateYesNo
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboCorporateIndex
                .DataSource = dvCorporateIndex
                .ValueMember = "contact_id"
                .DisplayMember = "company"
            End With
            With cmboCSalutation1
                .DataSource = dvCSalutation1
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboCSalutation2
                .DataSource = dvCSalutation2
                .ValueMember = "field_order"
                .DisplayMember = "field_description"
            End With
            With cmboACHBank
                .DataSource = dvACHBanks
                .ValueMember = "bank_id"
                .DisplayMember = "bank_description"
            End With
            With cmboACHBankABANum
                .DataSource = dvACHBankABAs
                .ValueMember = "bank_aba_id"
                .DisplayMember = "bank_aba_num"
            End With
            With cmboACHTransactionCode
                .DataSource = dvACHTransactionCodes
                .ValueMember = "transaction_code_id"
                .DisplayMember = "transaction_code_description"
            End With
        Catch ex As Exception
            HandledExceptionManager.EmailError = True
            HandledExceptionManager.ShowDialog(glUserInitials, ex, GetEmailDefaults(glCompany, glUserInitials))
            glValueUpdated = False
            glSavedEvent = True
        End Try
    End Sub

    Private Sub PopulateMemberTab()
        Try
            glNewContact = False
            dtIndex.Dispose()
            Dim da As New SqlDataAdapter
            Dim ds As New DataSet
            da.SelectCommand = New SqlCommand
            da.SelectCommand.Connection = TSFConnection
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.CommandText = "SPS_SelectContactEntry_EDU"
            da.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", glCompany))
            da.SelectCommand.Parameters.Add(New SqlParameter("@ContactID", glContactID))
            da.Fill(ds, "contact")
            dtIndex = ds.Tables(0)

            If dtIndex.Rows.Count > 0 Then
                cmboContactID.Text = glContactID
                cmboContactIndex.Text = dtIndex.Rows(0)("contact_index").ToString
                txtIndex.Text = dtIndex.Rows(0)("contact_index").ToString
                cmboContactType.Text = dtIndex.Rows(0)("contact_type_description").ToString
                UpdateFromContactType()
                cmboSalutation.Text = dtIndex.Rows(0)("salutation_description").ToString
                txtFirstName.Text = dtIndex.Rows(0)("first_name").ToString
                txtInitial.Text = dtIndex.Rows(0)("initial").ToString
                txtLastName.Text = dtIndex.Rows(0)("last_name").ToString
                txtCompany.Text = dtIndex.Rows(0)("company").ToString
                txtAddress1.Text = dtIndex.Rows(0)("address1").ToString
                txtAddress2.Text = dtIndex.Rows(0)("address2").ToString
                txtCity.Text = dtIndex.Rows(0)("city").ToString
                txtState.Text = dtIndex.Rows(0)("state").ToString
                txtZipCode.Text = dtIndex.Rows(0)("zip_code").ToString
                txtCityStateZipCode.Text = dtIndex.Rows(0)("city_state_zip_code").ToString
                txtCorrespondenceCompany.Text = dtIndex.Rows(0)("correspondence_company").ToString
                txtCorrespondenceContact.Text = dtIndex.Rows(0)("correspondence_contact").ToString
                txtCorrespondenceAddress1.Text = dtIndex.Rows(0)("correspondence_address1").ToString
                txtCorrespondenceAddress2.Text = dtIndex.Rows(0)("correspondence_address2").ToString
                txtCorrespondenceCity.Text = dtIndex.Rows(0)("correspondence_city").ToString
                txtCorrespondenceState.Text = dtIndex.Rows(0)("correspondence_state").ToString
                txtCorrespondenceZipCode.Text = dtIndex.Rows(0)("correspondence_zip_code").ToString
                txtBillingCompany.Text = dtIndex.Rows(0)("billing_company").ToString
                txtBillingContact.Text = dtIndex.Rows(0)("billing_contact").ToString
                txtBillingAddress1.Text = dtIndex.Rows(0)("billing_address1").ToString
                txtBillingAddress2.Text = dtIndex.Rows(0)("billing_address2").ToString
                txtBillingCity.Text = dtIndex.Rows(0)("billing_city").ToString
                txtBillingState.Text = dtIndex.Rows(0)("billing_state").ToString
                txtBillingZipCode.Text = dtIndex.Rows(0)("billing_zip_code").ToString
                cmboCSalutation1.Text = dtIndex.Rows(0)("c_salutation_description1").ToString
                cmboCSalutation2.Text = dtIndex.Rows(0)("c_salutation_description2").ToString
                txtCFirstName1.Text = dtIndex.Rows(0)("c_first_name1").ToString
                txtCFirstName2.Text = dtIndex.Rows(0)("c_first_name2").ToString
                txtCInitial1.Text = dtIndex.Rows(0)("c_initial1").ToString
                txtCInitial2.Text = dtIndex.Rows(0)("c_initial2").ToString
                txtCLastName1.Text = dtIndex.Rows(0)("c_last_name1").ToString
                txtCLastName2.Text = dtIndex.Rows(0)("c_last_name2").ToString
                txtEmail.Text = dtIndex.Rows(0)("email").ToString
                txtPhone.Text = FormatPhone(dtIndex.Rows(0)("phone").ToString)
                txtAltPhone.Text = FormatPhone(dtIndex.Rows(0)("alt_phone").ToString)
                txtCellPhone.Text = FormatPhone(dtIndex.Rows(0)("cell_phone").ToString)
                txtFax.Text = FormatPhone(dtIndex.Rows(0)("fax").ToString)
                If IsDate(dtIndex.Rows(0)("birthday")) Then
                    txtBirthday.Text = Format(dtIndex.Rows(0)("birthday"), "MM/dd/yyyy")
                End If
                txtSpouse.Text = dtIndex.Rows(0)("spouse").ToString
                txtSSNum.Text = dtIndex.Rows(0)("ss_num").ToString

                glFromDuesDropDown = False
                cmboDuesCategory.Text = dtIndex.Rows(0)("assessment_category_description").ToString
                'UpdateFromAssessmentCategory()
                cmboPaymentTerms.Text = dtIndex.Rows(0)("payment_term_description").ToString
                chkRecurringPayments.Checked = dtIndex.Rows(0)("recurring_payments_allowed").ToString

                txtJoinDate.Text = Format(dtIndex.Rows(0)("join_date"), "MM/dd/yyyy")
                cmboStatus.Text = dtIndex.Rows(0)("active_status_description").ToString

                lblPending.Visible = False
                Select Case dtIndex.Rows(0)("status_id")
                    Case 1 ' Active
                        lblRenewalDate.Visible = True
                        If IsDate(dtIndex.Rows(0)("renewal_date")) Then
                            txtRenewalDate.Text = Format(dtIndex.Rows(0)("renewal_date"), "MM/dd/yyyy")
                        Else
                            txtRenewalDate.Text = "  /  /"
                        End If
                        txtRenewalDate.Visible = True
                        cmdRenewalDateCalendar.Visible = True
                        txtReactivationDate.Text = "  /  /"
                        lblReactivationDate.Visible = False
                        txtReactivationDate.Visible = False
                        txtInactivationDate.Text = "  /  /"
                        lblInactivationDate.Visible = False
                        txtInactivationDate.Visible = False
                        cmdReactivationDateCalendar.Visible = False
                    Case 2, 4, 5 ' Inactive
                        If IsDate(dtIndex.Rows(0)("inactivation_date")) Then
                            txtInactivationDate.Text = Format(dtIndex.Rows(0)("inactivation_date"), "MM/dd/yyyy")
                        Else
                            txtInactivationDate.Text = "  /  /"
                        End If
                        lblRenewalDate.Visible = False
                        txtRenewalDate.Visible = False
                        cmdRenewalDateCalendar.Visible = False
                        txtReactivationDate.Text = "  /  /"
                        lblReactivationDate.Visible = False
                        txtReactivationDate.Visible = False
                        lblInactivationDate.Visible = True
                        txtInactivationDate.Visible = True
                        cmdReactivationDateCalendar.Visible = True
                    Case 3 'Reactivated
                        If IsDate(dtIndex.Rows(0)("reactivation_date")) Then
                            txtReactivationDate.Text = Format(dtIndex.Rows(0)("reactivation_date"), "MM/dd/yyyy")
                        Else
                            txtReactivationDate.Text = "  /  /"
                        End If
                        If IsDate(dtIndex.Rows(0)("renewal_date")) Then
                            txtRenewalDate.Text = Format(dtIndex.Rows(0)("renewal_date"), "MM/dd/yyyy")
                        Else
                            txtRenewalDate.Text = "  /  /"
                        End If
                        lblRenewalDate.Visible = True
                        txtRenewalDate.Visible = True
                        cmdRenewalDateCalendar.Visible = True
                        txtInactivationDate.Text = "  /  /"
                        lblInactivationDate.Visible = False
                        txtInactivationDate.Visible = False
                        lblReactivationDate.Visible = True
                        txtReactivationDate.Visible = True
                        cmdReactivationDateCalendar.Visible = True
                    Case 6 'Pending
                        lblPending.Visible = True
                        txtRenewalDate.Text = "  /  /"
                        If IsDate(dtIndex.Rows(0)("renewal_date")) Then
                            txtRenewalDate.Text = Format(dtIndex.Rows(0)("renewal_date"), "MM/dd/yyyy")
                        Else
                            txtRenewalDate.Text = "  /  /"
                        End If
                        lblRenewalDate.Visible = True
                        txtRenewalDate.Visible = True
                        cmdRenewalDateCalendar.Visible = True
                        txtReactivationDate.Text = "  /  /"
                        lblReactivationDate.Visible = False
                        txtReactivationDate.Visible = False
                        txtInactivationDate.Text = "  /  /"
                        lblInactivationDate.Visible = False
                        txtInactivationDate.Visible = False
                        cmdReactivationDateCalendar.Visible = False
                End Select
                cmboRecordEntryType.Text = dtIndex.Rows(0)("record_entry_type_description").ToString
                If dtIndex.Rows(0)("ach_active") Then
                    lblACHActive.Visible = True
                Else
                    lblACHActive.Visible = False
                End If
                'CalculateAccountBalance()
                If dtIndex.Rows(0)("dues_override_active").ToString = "Yes" Then
                    If IsNumeric(dtIndex.Rows(0)("dues_amount_override")) Then
                        txtDuesAmountOverride.Text = Format(dtIndex.Rows(0)("dues_amount_override"), "C").ToString
                    Else
                        txtDuesAmountOverride.Text = "$0.00"
                    End If
                    txtDuesAmountOverride.BackColor = System.Drawing.SystemColors.Window
                    txtDuesAmountOverride.ReadOnly = False
                    txtDuesAmountOverride.TabStop = True
                Else
                    txtDuesAmountOverride.Text = "$0.00"
                    txtDuesAmountOverride.BackColor = System.Drawing.SystemColors.Control
                    txtDuesAmountOverride.ReadOnly = True
                    txtDuesAmountOverride.TabStop = False
                End If
                txtCreated.Text = Format(dtIndex.Rows(0)("add_date"), "MM/dd/yyyy hh:mm tt").ToString & " by '" & dtIndex.Rows(0)("add_user_initials").ToString & "'"
                txtLastModified.Text = Format(dtIndex.Rows(0)("modified_date"), "MM/dd/yyyy hh:mm tt").ToString & " by '" & dtIndex.Rows(0)("modified_user_initials").ToString & "'"
                ' Search Form is loaded, set pointer to appropriate row & set glCurrentContactEntryRow
                If myFormsList.ContainsKey(90) And Misc_SearchRecs.Instance.glContactFromSearch Then
                    GetUserTableSortOrderValues()
                    Dim j As Int64 = 1, vals(Convert.ToInt16(dvTableSortOrder(0)("field_count").ToString) - 1) As Object, xField As String = "", xField2 As Long = 0, xEndWhile As Boolean = True
                    Dim varBaseName As String = "glSortOrderFieldType"
                    Dim varName, value As String
                    Dim T As Type = Me.GetType
                    Dim fi As FieldInfo
                    For j = 1 To 6
                        varName = varBaseName & j
                        fi = T.GetField(varName, BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic)
                        If fi.GetValue(Me) = "" Or fi.GetValue(Me) = " " Then
                            Exit For
                        Else
                            value = fi.GetValue(Me) '.ToString
                            Select Case value
                                Case "d"
                                    xField = Format(CDate(CType(GetLocalControl(dvTableSortOrder(0)("form_field_name" & Trim(Str(j))).ToString), MaskedTextBox).Text), "MM/d/yyyy hh:mm:ss tt")
                                Case "t"
                                    xField = CType(GetLocalControl(dvTableSortOrder(0)("form_field_name" & Trim(Str(j))).ToString), TextBox).Text
                                Case "c"
                                    xField = CType(GetLocalControl(dvTableSortOrder(0)("form_field_name" & Trim(Str(j))).ToString), ComboBox).Text
                                Case "n"
                                    xField = CLng(CType(GetLocalControl(dvTableSortOrder(0)("form_field_name" & Trim(Str(j))).ToString), TextBox).Text)
                            End Select
                            vals(j - 1) = xField
                        End If
                    Next
                    j = dvGlobalContacts.Find(vals)
                    If j >= 0 Then
                        glCurrentContactEntryRow = j
                    Else
                        glCurrentContactEntryRow = 0
                    End If
                    Misc_SearchRecs.Instance.glContactFromSearch = False
                End If
                bSave.Enabled = False
                bCopy.Enabled = True
                bDelete.Enabled = True
                bBrowse.Enabled = True
                bPrint.Enabled = True
            End If
        Catch ex As Exception
            HandledExceptionManager.EmailError = True
            HandledExceptionManager.ShowDialog(glUserInitials, ex, GetEmailDefaults(glCompany, glUserInitials))
            glValueUpdated = False
            glSavedEvent = True
            Me.Close()
        End Try
    End Sub



Stored Procedure
/****** Object:  StoredProcedure [dbo].[SPS_SelectContactEntry_EDU]    Script Date: 05/14/2011 13:21:03 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[SPS_SelectContactEntry_EDU]
@CompanyID bigint, 
@ContactID bigint
AS
SELECT a.*, 
CASE WHEN i.dues_override = 1 THEN 'Yes' ELSE 'No' END as dues_override_active, 
CASE WHEN a.corporate_yesno_id = 1 THEN 'Yes' ELSE 'No' END AS corporate_yesno_description, 
CASE WHEN a.corporate_yesno_id = 0 THEN '' ELSE corp.company END AS corporate_index, 
b.field_description AS contact_type_description, 
sal1.field_description AS salutation_description, 
sal2.field_description AS c_salutation_description1, 
sal3.field_description AS c_salutation_description2, 
d.field_description AS member_category_description, 
e.field_description AS record_entry_type_description, 
f.field_description AS county_description, 
g.field_description AS school_district_description, 
h.area_district_description, 
i.assessment_category_description, 
k.field_description AS recruiter_type_description, 
l.asc_name AS recruited_by_area_director_description, 
m.field_description AS active_status_description, 
n.field_description AS payment_term_description, 
building_rep.field_description AS building_rep_description
FROM contact a
LEFT OUTER JOIN tbl_contact_type b ON a.contact_type_id = b.field_order
LEFT OUTER JOIN tbl_salutation sal1 ON a.salutation_id = sal1.field_order
LEFT OUTER JOIN tbl_salutation sal2 ON a.c_salutation_id1 = sal2.field_order
LEFT OUTER JOIN tbl_salutation sal3 ON a.c_salutation_id2 = sal3.field_order
LEFT OUTER JOIN tbl_member_category d ON a.company_id = d.company_id AND a.member_category_id = d.field_order
LEFT OUTER JOIN tbl_record_entry_type e ON a.record_entry_type_id = e.field_order
LEFT OUTER JOIN tbl_county f ON a.company_id = f.company_id AND a.county_id = f.field_order
LEFT OUTER JOIN tbl_school_district g ON a.company_id = f.company_id AND a.school_district_id = g.field_order
LEFT OUTER JOIN tbl_area_district h ON a.company_id = h.company_id AND a.area_district_id = h.area_district_id
LEFT OUTER JOIN tbl_assessment_category i ON a.company_id = i.company_id AND a.assessment_category_id = i.assessment_category_id
LEFT OUTER JOIN tbl_recruiter_type k ON a.recruiter_type_id = k.field_order
LEFT OUTER JOIN tbl_area_director l ON a.company_id = l.company_id AND a.recruited_by_area_director_id = l.area_director_id
LEFT OUTER JOIN tbl_member_active_status m ON a.status_id = m.field_order
LEFT OUTER JOIN tbl_payment_term n ON a.payment_term_id = n.field_order
LEFT OUTER JOIN tbl_yesno building_rep ON a.building_rep_id = building_rep.field_order
LEFT OUTER JOIN contact corp ON a.company_id = corp.company_id AND a.corporate_contact_id = corp.contact_id
WHERE (a.contact_id = @ContactID)

Open in new window

Author

Commented:
The comboboxes originally has the following entries replaced in the PopulateFields:

                cmboContactID.SelectedValue = glContactID
                cmboContactIndex.SelectedValue = glContactID
                cmboContactType.SelectedValue = dtIndex.Rows(0)("contact_type_id")
                cmboSalutation.SelectedValue = dtIndex.Rows(0)("salutation_id")
                cmboCSalutation1.SelectedValue = dtIndex.Rows(0)("c_salutation_id1")
                cmboCSalutation2.SelectedValue = dtIndex.Rows(0)("c_salutation_id2")
                cmboDuesCategory.SelectedValue = dtIndex.Rows(0)("assessment_category_id")
                cmboPaymentTerms.SelectedValue = dtIndex.Rows(0)("payment_term_id")
                cmboStatus.SelectedValue = dtIndex.Rows(0)("active_status_id")
                cmboRecordEntryType.SelectedValue = dtIndex.Rows(0)("record_entry_type_id")
Most Valuable Expert 2012
Top Expert 2014

Commented:
Wow. How long does this form take to load? Are you using a tab control? Show a screenshot of UI. My initial though is that you are calling too many methods.

Author

Commented:
Sorry for the delay.  New Windows 7 machine.  My CaptureEZE Pro will not save.  Had to use alternate PC.

On this new I5 machine...takes 1 second to load.  P4 3ghz...takes 3 seconds.


Capture.jpg
Most Valuable Expert 2012
Top Expert 2014

Commented:
In my forms, when I use tabs, I load tabs on demand. I only load 1st tab in form load and then load rest of the tabs when the user selects a tab (user may not look at any other tab and you are loading 9 tabs)

Author

Commented:
Did you notice that only two tabs are enabled???

Once a valid record has been chosen, I enable all of the tabs.  However, until the tab has been selected the first time, do I load up any dataviews or gridviews with data.
Most Valuable Expert 2012
Top Expert 2014

Commented:
>Did you notice that only two tabs are enabled???
I did.

>However, until the tab has been selected the first time, do I load up any dataviews or gridviews with data.

Do you mean "Should I populate all the dataviews?" ?

Author

Commented:
Sorry.  Needed to phrase it a little different.  I DO NOT load dataviews or gridviews with data until selected the first time.  My bad.

I was also about to write....I do load dataviews and set datasources for comboboxes on the second tab initially in Form_Load/BuildTablesandViews because tabs 1 & 2 are viewed/edited 99% of the time when a member record is populated.

Author

Commented:
Once again, I need to re-phrase.  I do not load/refresh the dataviews or gridviews with subsequent data on the other tabs unless it that tab has been clicked or is the ACTIVE tab when selecting a new member record.  Note the included code.
Private Sub Tab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MemberTab1.SelectedIndexChanged
        If Me.MemberTab1.SelectedTab.Equals(Me.CorrespondenceTabPage) = True Then
            If glCorrClicked = True Then
                Exit Sub
            Else
                xRefreshCorrespondenceGrid()
                glCorrClicked = True
            End If
        ElseIf Me.MemberTab1.SelectedTab.Equals(Me.CommitteeTabPage) = True Then
            If glCommitteeClicked = True Then
                Exit Sub
            Else
                Activating = True
                xRefreshCommitteeMembershipGrid()
                glCommitteeClicked = True
                Activating = False
            End If
        ElseIf Me.MemberTab1.SelectedTab.Equals(Me.MiscPositionTabPage) = True Then
            If glMiscPositionClicked = True Then
                Exit Sub
            Else
                Activating = True
                xRefreshMiscPositionGrid()
                glMiscPositionClicked = True
                Activating = False
            End If
        ElseIf Me.MemberTab1.SelectedTab.Equals(Me.PublicationsTabPage) = True Then
            If glPubClicked = True Then
                Exit Sub
            Else
                xRefreshPublicationsGrid()
                glPubClicked = True
            End If
        ElseIf Me.MemberTab1.SelectedTab.Equals(Me.AccountingTabPage) = True Then
            If glAccClicked = True Then
                Exit Sub
            Else
                xRefreshAccountingGrid()
                glAccClicked = True
                If dvCustomerAccounting.Count > 0 Then
                    'set first rec as selected
                    'grdviewaccounting.SelectedRows.
                    grdviewAccounting.Rows(0).Selected = False
                End If
            End If
        ElseIf Me.MemberTab1.SelectedTab.Equals(Me.ACHTabPage) = True Then
            If glACHClicked = True Then
                Exit Sub
            Else
                Activating = True
                xRefreshACHGrid()
                Activating = False
                glACHClicked = True
            End If
        End If
    End Sub

    Private Sub PopulateFields()
        Me.Cursor = Cursors.Arrow

        If Not MemberTab1.TabPages.Item(2).Enabled Then
            MemberTab1.EnablePage(MemberTab1.TabPages.Item(2))
            MemberTab1.EnablePage(MemberTab1.TabPages.Item(3))
            MemberTab1.EnablePage(MemberTab1.TabPages.Item(4))
            MemberTab1.EnablePage(MemberTab1.TabPages.Item(5))
            MemberTab1.EnablePage(MemberTab1.TabPages.Item(6))
            If glACHLevels = "T" Then
                MemberTab1.EnablePage(MemberTab1.TabPages.Item(7))
            End If
            MemberTab1.EnablePage(MemberTab1.TabPages.Item(8))
        End If

        ' MEMBER TAB FIELDS
        PopulateMemberTab()
        ' EDUCATIONAL TAB FIELDS
        PopulateEducationalTab()
        ' CORRESPONDENCE TAB FIELDS
        If glCorrClicked Then
            xRefreshCorrespondenceGrid()
        End If
        ' COMMITTEE MEMBERSHIP TAB FIELDS
        If glCommitteeClicked Then
            xRefreshCommitteeMembershipGrid()
        End If
        ' MISC. POSITIONS TAB FIELDS
        If glMiscPositionClicked Then
            xRefreshMiscPositionGrid()
        End If
        ' PUBLICATION TAB FIELDS
        If glPubClicked Then
            xRefreshPublicationsGrid()
        End If
        ' ACCOUNTING TAB FIELDS
        If glAccountingMgmt Then
            If glAccClicked Then
                xRefreshAccountingGrid()
            End If
        End If
        ' ACH TAB FIELDS
        If glACHClicked Then
            xRefreshACHGrid()
        End If
        ' NOTES TAB FIELD
        PopulateNotesTab()
    End Sub

Open in new window

Most Valuable Expert 2012
Top Expert 2014
Commented:
The short answer is you need to reduce and optimize the code on form load. Now I expect you to say that "that is exactly what I am asking" but the trouble is it would be very difficult for me to suggest improvements in code without understand the full application, the data being accessed, the structure of code etc.

Some generic improvements include

1) Move all the permissions code to a separate single sub ApplyPermissions() and call that from form load. Also, do not load the lists if the user does not have permission to change them etc.

2) You can use a single stored procedure to populate all the lists. It would be a long procedure but would reduce a lot of overhead. Then use that procedure to fill datatables within a single dataset. Why are you using separate dataviews?

3) I see you have a bindingnavigator on top but you are populating the details manually using the stored procedure. What is going on there?

Author

Commented:

>> 1) Move all the permissions ....

No problem.

>> 2) You can use a single stored procedure to populate all the lists.
>> 2) Then use that procedure to fill datatables within a single dataset. Why are you using separate dataviews?

How in the #(*^! do you do this?  I was unaware you could do this.  Can you provide a short example/link.  
Something tells me this is where using a table# or tablename in the following comes into play.
dt = ds.Tables("table_name" OR #)

3) I see you have a bindingnavigator on top but you are populating the details manually using the stored procedure. What is going on there?

I attempted to use a bound navigator (?) in VB and had immortal problems with it.  At the time I was just getting my feet wet with VB.  Could be a completely different story now.  If you want me to start another posting(s) for #2 & #3 for points/effort, I will be glad to.



Just continuing to use what I learned starting in 2006.  Probably could optimize many things if I was better versed.
Thanks.
Most Valuable Expert 2012
Top Expert 2014

Commented:
>How in the #(*^! do you do this?  I was unaware you could do this.  Can you provide a short example/link.

This is called Multiple Active Result Sets (MARS).

Example with DataReader
http://vb.net-informations.com/ado.net-dataproviders/ado.net-multiple-result-sets.htm

Example with DataSet
http://ondotnet.com/pub/a/dotnet/2002/12/16/multiresultsets_1202.html?page=2
Most Valuable Expert 2012
Top Expert 2014

Commented:
For point 3, you can use the navigator if same form is being used to edit multiple members by just navigating around but if you are using a form with grid and then opening this form with details then you dont need the navigator. Also, you are using a datatable to load the single member details, datareader would be more suitable choice in this scenario.

Author

Commented:
I'm excited about the multi-table capability to the point that the words are getting blurry.  :)  Very much appreciated.
I only have one concern.  I allow the user to add values to 4-5 of the comboboxes by activating a messagebox & combobox field-specific form for validation.  This wouldn't happen very often at all, but I'm assuming I would need to refresh the dataview I use during Form_Load associated with the MARS in order to update that specific table rowset.

>> For point 3 (DataReader)
If I'm reading properly and to respond.  
I DO have a "Search Members" form which can be the starting point.  A user can perform a search which filters a list of member recs in a grid.  Then the user can double-click on one of those rows in the grid which will then activate the "Member Entry" form we have been working with.
Also, if the starting point IS the "Member Entry" form, I have a 'Browse' button on the button menu that will pull up a separate "Browse Form" with all the member records in a grid.  The selected row will be the row for the current "Member Entry" form record.  The user can then move up and down through the grid, double-click on another row...which in turn re-activates the "Member Entry" form and with the Form_Activated sub I re-populate the form with the newly selected member record.

To Note....
The "Search Members" form remains open when a user double-clicks a row and activates the "Member Entry" form.  I refresh the Search form upon update of member rec.
The "Browse Form" does not stay open when a user double-clicks a row.

Also, I did know I could populate member details from the datareader if I was using it.

I only have one more issue with the best/most efficient way to refresh the datareader recordset upon update of the current member record.  Just refresh the recordset bound to the reader?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Your member entry form can then be switched to using a DataReader. I am not sure how much difference it would make with regards to resource requirement though.

Not sure if I understand your first part.

Author

Commented:
I think I would stick with the way I handle my navigation between recs.  It works well, and I don't think it requires much in the way of resources.  The only thing is that I wouldn't be able to eleviate the need for manual SQL select on populating member details.  May have to test it.

Otherwise, we'll leave it at that.

Thanks for all the time invested.
Phil
Most Valuable Expert 2012
Top Expert 2014

Commented:
Glad to help :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial