I realize that the response time of my GUI is extremely slow! I have three combo boxes - I want the user to select a template from one drop down list, which will populate the second drop down list with customers related to that template. When a customer is selected, the third drop down list is to be populated with items related to that customer.
Each code snippet that selects the next level (template -> customer; customer -> item) is stored in a separate procedure:
Private Sub SelectTemplate()
'User selects the template desired from the drop down list
Try
Select Case cboTemplate.Text
Case Is = "South"
SQL_Text = "SELECT itemno, [item desc], barcode, cat, baseunit, stockunit FROM SBI_SOUTH_CUST_ITEMS"
End Select
RegionString = SQL_Text
Catch ex As Exception
MessageBox.Show("Error:" & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub PopulateCustList()
'Shows list of customers in Customers drop down list
Dim SelectCust As String
Try
SelectCust = "SELECT * FROM OTM_SOUTH_CUSTOMERS"
Dim SQLCom As New SqlCommand(SelectCust, SQLCon)
da = New SqlDataAdapter(SelectCust, SQLCon)
da.Fill(Custds, "cust")
CustomerLoading = True 'Set flag on
cboCustomer.DataSource = Custds.Tables("cust")
cboCustomer.DisplayMember = "name"
CustomerLoading = False 'Set flag off
Catch ex As Exception
MessageBox.Show("Error:" & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Private Sub ShowCustomerDetails()
'Show items details for specific customers in Items drop down list
Dim da As SqlDataAdapter
Dim dt As New DataSet
Try
Dim SQLCom As New SqlCommand(SQL_Text, SQLCon)
da = New SqlDataAdapter(SQL_Text, SQLCon)
da.Fill(dt, "details")
dgView.DataSource = dt.Tables("details")
dgView.AutoResizeColumns()
ItemLoading = True
cboItem.DataSource = dt.Tables(0)
cboItem.DisplayMember = "item desc"
ItemLoading = False
Catch ex As Exception
MessageBox.Show("Error:" & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Those procedures are called from the SelectIndexChanged events of cboTemplate and cboCustomer, respectfully.
I find that in my testing, these SelectIndexChanged events are fired numerous times - every time I add a DataSource, every time I add a DisplayMember.
I need to code this logic in such a way that the GUI does not hang for 5 seconds each time a user makes a change. What can I use other than SelectIndexChanged?
(One way I tried to get around this is the boolean CustomerLoading and ItemLoading. I change them to True when the datasource and displaymember are being loaded and false otherwise, and try to skip the myriad times the procedures are fired by testing for a False value in the SelectIndexChanged, but either I'm not doing it right, or I'm missing something.)
Please assist!