Combobox.FindStringExact--doesn't find text that I KNOW is there.

  • Thread starter Thread starter rdi
  • Start date Start date
R

rdi

I've got a combo-box of the drop-down style (not drop-down-list). The first item is "NHPI-Forms". If I type "NHPI-Forms" into the combo-box that string is supposedly not listed in the combo-box. While if I type "Personal" (which is the THIRD item in the list, it IS found. I'm using "FindStringExact" from the combo-box. WHat could be going on?


TIA

--

RDI

(remove the exclamation from the email address)


'This is performed as part of the initialization of the form
cbxAcctAcctList.Items.Add("NHPI-Forms")
cbxAcctAcctList.Items.Add("NHPI-AutoResponder")
cbxAcctAcctList.Items.Add("Personal")

'This is what happens if I type something into the combobox.
'If I type "NHPI-Forms", the FIRST portion of the IF statement occurs
'if I type "Personal", the SECOND portion of the IF statement occurs
Private Sub cbxAcctAcctList_NewText(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxAcctAcctList.TextChanged
If cbxAcctAcctList.FindStringExact(cbxAcctAcctList.Text) Then
BtnAcctRmv.Enabled = True
btnAcctMod.Enabled = True
btnAcctAdd.Enabled = False
Else
BtnAcctRmv.Enabled = False
btnAcctMod.Enabled = False
btnAcctAdd.Enabled = True
End If
End Sub
 
Never mind. Shortly after hitting send, the answer hit me. Find string returns an integer. If the string is NOT found, it returns -1. If it IS found, it returns the index to it.

The following worked fine.

Private Sub cbxAcctAcctList_NewText(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxAcctAcctList.TextChanged
If cbxAcctAcctList.FindStringExact(cbxAcctAcctList.Text) >= 0 Then
BtnAcctRmv.Enabled = True
btnAcctMod.Enabled = True
btnAcctAdd.Enabled = False
Else
BtnAcctRmv.Enabled = False
btnAcctMod.Enabled = False
btnAcctAdd.Enabled = True
End If
End Sub

--

RDI

(remove the exclamation from the email address)

I've got a combo-box of the drop-down style (not drop-down-list). The first item is "NHPI-Forms". If I type "NHPI-Forms" into the combo-box that string is supposedly not listed in the combo-box. While if I type "Personal" (which is the THIRD item in the list, it IS found. I'm using "FindStringExact" from the combo-box. WHat could be going on?


TIA

--

RDI

(remove the exclamation from the email address)


'This is performed as part of the initialization of the form
cbxAcctAcctList.Items.Add("NHPI-Forms")
cbxAcctAcctList.Items.Add("NHPI-AutoResponder")
cbxAcctAcctList.Items.Add("Personal")

'This is what happens if I type something into the combobox.
'If I type "NHPI-Forms", the FIRST portion of the IF statement occurs
'if I type "Personal", the SECOND portion of the IF statement occurs
Private Sub cbxAcctAcctList_NewText(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxAcctAcctList.TextChanged
If cbxAcctAcctList.FindStringExact(cbxAcctAcctList.Text) Then
BtnAcctRmv.Enabled = True
btnAcctMod.Enabled = True
btnAcctAdd.Enabled = False
Else
BtnAcctRmv.Enabled = False
btnAcctMod.Enabled = False
btnAcctAdd.Enabled = True
End If
End Sub
 
I tried it and it returned 0, which is correct. So your if statement
will return False because 0 is considered False.

'-- Will be false if number is zero
If cbxAcctAcctList.FindStringExact(cbxAcctAcctList.Text) Then

'-- You should change it to this:
If cbxAcctAcctList.FindStringExact(cbxAcctAcctList.Text) > -1 Then
 
Back
Top