Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box - selectedtext property - always ""

Status
Not open for further replies.

rushdib

Programmer
Jun 12, 2001
203
US
Hi,
I have form with a combo box. When the form is activated, i am moving "" to the combo box, otherwise it always show the first item in the list.
Now I am trying to find whether the user has typed in, selected an item or left the combo box blank. The selectedtext property always brings a value "". The selecteditem gives me an error. Can someone please help me?

Thanks in advance,

Rushdi
 
The activated event will occur every time the form gets focus from another form in the application, not just once after it is loaded.

SelectedItem returns Nothing if no item is selected so you can not access any properties until you have checked it.
if not(.SelectedItem Is Nothing) then
...... Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Hi John,
I tried the condition if not (combobox.SelectedItem is Nothing), it is always true. So there is always a value in the combobox eventhough it is blank at the text level. I even tried combobox.text property, and it always shows the first item in the combo box eventhough the user never selected or entered.
 
Is it a DropDownList?

Doc says:
Public Property SelectedText As String
Property Value
A string that represents the currently selected text in the combo box. If DropDownStyle is set to ComboBoxStyle.DropDownList, the return is an empty string ("").
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
dropdownstyle property is set to dropdown not dropdownlist.
 
After I run the code above, strW has "System.Data.DataRowView"
 
I do not know what to tell you then. Here is the example from the DOCS.

Private Sub showSelectedButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim selectedIndex As Integer
selectedIndex = comboBox1.SelectedIndex
Dim selectedItem As Object
selectedItem = comboBox1.SelectedItem

MessageBox.Show("Selected Item Text: " & selectedItem.ToString() & Microsoft.VisualBasic.Constants.vbCrLf & _
"Index: " & selectedIndex.ToString())
End Sub

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
On second thought, "System.Data.DataRowView" tells me that your combobox items collection does not contain strings but rather "System.Data.DataRowView" items. I have not yet dealt with storing objects other than strings in combobox or list so I can not not help you. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top