Why would a combox give a different result in the environment from the compiled version

Kath Varcoe 0 Reputation points
2023-02-12T20:13:32.6133333+00:00

windows.forms.combobox always returns 1 when run compiled on a Windows 10 machine. It returns the correct answer in the development environment and compiled and run on a Windows 7 virtual machine.

Program is compiled as 'any cpu'. It complains about one project that it references that is compiled for x86


 Private Sub LoadLocations()
        'gets locations that this provider is registered with HIC, either in or out of hospital

        Dim snpFee As DataTable
        Dim sql As String

        sql = $"SELECT L.counter, L.LocationName  
                FROM Providers as P INNER JOIN Locations as L ON P.ctrLocation = L.counter 
                WHERE (L.loc_Hidden = 0 Or L.loc_Hidden Is Null) 
                    AND (P.ProviderNumber <> '' 
                    AND Not P.ProviderNumber Is Null)  
                    AND P.ctrUser = {mctrUser}"

        If mInHospital Then
            sql &= " AND loc_HICTreatmentLocationCde = 'H'"
            lblLocation.Text = "Location (In Hospital)"
        Else
            sql &= " AND loc_HICTreatmentLocationCde <> 'H'"
            lblLocation.Text = "Location (Out of Hospital)"
        End If

        sql &= " ORDER BY L.counter DESC"

        snpFee = mSPMDA.GetSQLDatatable(sql)

        If Not snpFee Is Nothing AndAlso snpFee.Rows.Count > 0 Then
            cmbLocations.DataSource = snpFee
            cmbLocations.ValueMember = "counter"
            cmbLocations.DisplayMember = "LocationName"

            cmbLocations.SelectedValue = mctrLocation
        Else
            lblMsg.Text = mSPMDA.ErrMessage
        End If

        cmbLocations.Refresh()

    End Sub

Private sub SaveInformation
.
.
.
.
        If cmbLocations.SelectedIndex = -1 Then
            cmbLocations.SelectedIndex = 0
        End If
        
        If IsNumeric(cmbLocations.SelectedValue) Then
            mctrLocation = CInt(cmbLocations.SelectedValue)
        Else
            mctrLocation = 0
        End If
.
.
.
End Sub
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | VB
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,766 Reputation points
    2023-02-13T16:17:58.1233333+00:00

    Hello there,

    There is the possibility that the ComboBox does not actually update its contents until there is an operation such as a UI refresh and hence the count will be off until that time.

    One case where this may happen is if you update the DataSource before the Handle is created for the ComboBox. It appears the items will not be updated in this case until the ComboBox is actually created and rendered.

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments

  2. Limitless Technology 44,766 Reputation points
    2023-02-13T16:18:09.9833333+00:00

    Double post

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.