|
-
Feb 6th, 2007, 01:41 PM
#1
Thread Starter
PowerPoster
[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,
-
Feb 6th, 2007, 02:08 PM
#2
Fanatic Member
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..."
-
Feb 6th, 2007, 06:26 PM
#3
Thread Starter
PowerPoster
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?
-
Feb 6th, 2007, 06:36 PM
#4
Addicted Member
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?
-
Feb 6th, 2007, 07:00 PM
#5
Thread Starter
PowerPoster
Re: ComboBox loses its value when clicked???
Here's my query:
VB Code:
Private Sub LoadTerminalComboBox()
Try
Dim iRow As DataRow
Dim tmpTerminal As String = ""
strProcedure = "LoadTerminalComboBox"
cmbTerminal.Items.Clear()
For Each iRow In dtBatchHeader.Rows
If iRow.Item("terminal") = Convert.ToString(tmpTerminal) Then
Else
cmbTerminal.Items.Add(iRow("terminal"))
tmpTerminal = iRow("terminal")
End If
Next
Catch ex As Exception
ErrorHandler(strProgram, strModule, strProcedure, Msg)
End Try
End Sub
All I'm doing is loading a combobox from a Datatable.
-
Feb 6th, 2007, 07:10 PM
#6
Addicted Member
Re: ComboBox loses its value when clicked???
VB Code:
Private Sub LoadTerminalComboBox()
Try
Dim iRow As DataRow
Dim tmpTerminal As String = ""
strProcedure = "LoadTerminalComboBox"
cmbTerminal.Items.Clear()
For Each iRow In dtBatchHeader.Rows
If iRow.Item("terminal") = Convert.ToString(tmpTerminal) Then
Else
cmbTerminal.Items.Add(iRow("terminal"))
tmpTerminal = iRow("terminal")
End If
Next
Catch ex As Exception
ErrorHandler(strProgram, strModule, strProcedure, Msg)
End Try
End Sub
Where are you calling this from? And I am not sure that I follow the logic statement your using.
VB Code:
if iRow.items("Terminal") = Convert.ToString(tmpTerminal) then
Is that like??????
VB Code:
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.
-
Feb 7th, 2007, 10:25 AM
#7
Thread Starter
PowerPoster
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.
-
Feb 8th, 2007, 10:54 AM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|