Results 1 to 8 of 8

Thread: [RESOLVED] ComboBox loses its value when clicked???

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [RESOLVED] ComboBox loses its value when clicked???

    I have a form that has several comboboxes on them. They are loaded with a single column from a table by a SQL Query. Problem is, when I click on the ComboBox and select a value....it goes blank and the ComboBox itself clears out. Why does this happen?

    Thanks,
    Blake

  2. #2
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: ComboBox loses its value when clicked???

    Set the valuemember and displaymember in the Properties Window. Usually the valuemember will a unique value, an ID of some sort. Display member is whatever you want it to be. To do this you must have them bound to a dataset in the IDE. If not then you must manually do it in the code.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: ComboBox loses its value when clicked???

    Why doesn't it work like VB6. Does it always clear out like that??? And since it's loaded with table data, how do I make the default value the 1st value?
    Blake

  4. #4
    Addicted Member Daystar's Avatar
    Join Date
    Dec 2006
    Location
    Pahrump, NV
    Posts
    132

    Re: ComboBox loses its value when clicked???

    What exactly are you trying to do? Use the Query to populate the Item Collection on the Combo Box?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: ComboBox loses its value when clicked???

    Here's my query:

    VB Code:
    1. Private Sub LoadTerminalComboBox()
    2.         Try
    3.             Dim iRow As DataRow
    4.             Dim tmpTerminal As String = ""
    5.  
    6.             strProcedure = "LoadTerminalComboBox"
    7.             cmbTerminal.Items.Clear()
    8.  
    9.             For Each iRow In dtBatchHeader.Rows
    10.                 If iRow.Item("terminal") = Convert.ToString(tmpTerminal) Then
    11.                 Else
    12.                     cmbTerminal.Items.Add(iRow("terminal"))
    13.                     tmpTerminal = iRow("terminal")
    14.                 End If
    15.             Next
    16.  
    17.         Catch ex As Exception
    18.             ErrorHandler(strProgram, strModule, strProcedure, Msg)
    19.         End Try
    20.     End Sub

    All I'm doing is loading a combobox from a Datatable.
    Blake

  6. #6
    Addicted Member Daystar's Avatar
    Join Date
    Dec 2006
    Location
    Pahrump, NV
    Posts
    132

    Re: ComboBox loses its value when clicked???

    VB Code:
    1. Private Sub LoadTerminalComboBox()
    2.         Try
    3.             Dim iRow As DataRow
    4.             Dim tmpTerminal As String = ""
    5.  
    6.             strProcedure = "LoadTerminalComboBox"
    7.             cmbTerminal.Items.Clear()
    8.  
    9.             For Each iRow In dtBatchHeader.Rows
    10.                 If iRow.Item("terminal") = Convert.ToString(tmpTerminal) Then
    11.                 Else
    12.                     cmbTerminal.Items.Add(iRow("terminal"))
    13.                     tmpTerminal = iRow("terminal")
    14.                 End If
    15.             Next
    16.  
    17.         Catch ex As Exception
    18.             ErrorHandler(strProgram, strModule, strProcedure, Msg)
    19.         End Try
    20.     End Sub

    Where are you calling this from? And I am not sure that I follow the logic statement your using.
    VB Code:
    1. if iRow.items("Terminal") = Convert.ToString(tmpTerminal) then

    Is that like??????
    VB Code:
    1. if not iRow.Items("Terminal").ToString = String.Empty

    Plus you clear the box everytime you clear this function. Even if it can not be repopulated.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: ComboBox loses its value when clicked???

    All this procedure does is read data from a DataTable. It checks each value of "terminal" and compares it to an empty variable tmpTerminal. If they match bypass that record and move the "terminal" into the tmpTerminal variable and compare another record.

    As far as cmbTerminal.Items.Clear....I'm assuming it clears out the ComboBox and reloads it via the For Next Loop.
    Blake

  8. #8
    Addicted Member Daystar's Avatar
    Join Date
    Dec 2006
    Location
    Pahrump, NV
    Posts
    132

    Re: ComboBox loses its value when clicked???

    Yes it should be cleared then reloaded. Unless nothing pass the IF Statement. But that is neither here nor there. Do you have any code on the combobox itself?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width