[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to capture selected values of a combobox who's datasource is a LIST (arrylist)

Posted on 2009-04-10
2
Medium Priority
?
272 Views
Last Modified: 2012-06-27
I am using a combo box to allow the user to change the view of a datagridview based on a value selected from the combobox (status). the datasource for the combobox is LIST as you can see below. When I open the form i am preloading the combobox to get it ready. For some reason I'm getting the error below when I open my form. I suspect the reason behind the error is the fact that I am using a LIST for datasource; consequently I am unable to read correctly the integer value of a selected status. So my question, how am i supposed to read the integer value for a selected status while the data source is a LIST?

Thank you,
Private Sub PopulateLookupComboBoxes()
 
        StatusList_Lookup = StatusDB.GetStatus
 
        Me.cboStatusLookup.DataSource = StatusList_Lookup
        Me.cboStatusLookup.ValueMember = "StatusID"
        Me.cboStatusLookup.DisplayMember = "StatusDesc"
        'Me.cboStatusLookup.SelectedValue = -1
End sub
 
 
Public Class StatusDB
    Public Shared Function GetStatus() As List(Of Status)
        Dim StatusList As New List(Of Status)
        Dim connection As SqlConnection = DBConnection.GetConnection(True)
 
        Dim selectStatement As String _
            = "Select pkStatusID, StatusDesc " _
            & "FROM tblStatus " _
            & "ORDER BY StatusDesc"
 
        Dim selectCommand As New SqlCommand(selectStatement, connection)
        Try
            connection.Open()
            Dim reader As SqlDataReader
            reader = selectCommand.ExecuteReader()
            Dim i As Integer
            i = reader.RecordsAffected
 
            Dim Status As Status
            Do While reader.Read
                Status = New Status
                Status.StatusID = CInt(reader("pkStatusID"))
                Status.StatusDesc = reader("StatusDesc").ToString
                StatusList.Add(Status)
            Loop
            reader.Close()
 
        Catch ex As Exception
            Throw ex
        End Try
        Return StatusList
    End Function
 
End Class
 
 
 
 
  Private Sub cboStatusLookup_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboStatusLookup.SelectedIndexChanged
        ProcessSearch("Status", Me.cboStatusLookup.SelectedValue)
    End Sub
 
Private Sub ProcessSearch(ByVal strFieldName As String, ByVal intFieldValue As Integer)
 
        Dim lngCurrentTicketID As Long
        Select Case strFieldName
 
            Case Is = "Status"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblTicketsQueue.fkStatus = " & intFieldValue & " "
 
            Case Is = "TicketID"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblTicketsQueue.pkTicketID = " & CLng(intFieldValue) & " "
 
            Case Is = "Employee"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblTicketsQueue.fkUser = " & CLng(intFieldValue) & " "
 
            Case Is = "Category"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblTicketsQueue.fkCategory = " & CLng(intFieldValue) & " "
 
            Case Is = "Product"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblTicketsQueue.fkProduct = " & CLng(intFieldValue) & " "
 
            Case Is = "Department"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblUsers.fkDepartmentID = " & CLng(intFieldValue) & " "
 
            Case Is = "TicketHolder"
                SQLWhere = "WHERE tblTicketsQueue.fkStatus NOT LIKE " & Statusclosed & " AND tblTicketsQueue.MarkForDeletion NOT LIKE 1 " _
                        & "AND tblUsers_1.fkUser = " & CLng(intFieldValue) & " "
        End Select
 
        Try
            TicketList = TicketsDB.GetTickets(SQLWhere, SQLOrderBy)
            DataGridViewTickets.DataSource = TicketList
            ArrangeGridData()
            LocateRecord(lngCurrentTicketID)
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)
        End Try
    End Sub

Open in new window

4-10-2009-10-23-22-AM.png
4-10-2009-10-25-46-AM.png
0
Comment
Question by:mkarkoukli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Author Comment

by:mkarkoukli
ID: 24118645
Another way to ask my question:  How do I stop cboStatusLookup_SelectedValueChanged event from firing when opening the form. It seems that when I load the datasource of the combobox It automatically fires the SelectValueChange event and when that happens there is nothing selected and as a result it causes the above error.
0
 

Accepted Solution

by:
mkarkoukli earned 0 total points
ID: 24118741
i found the solution:

http://www.vbforums.com/showthread.php?t=207065

Setting boolean value to true while the form is loading..
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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