get index of combobox (compare text)

N

Niels

Hello,
I'm trying to get te index of a specific text in a
ComboBox.
The ComboBox is filled by searching for filenames in a
directory.
The text of the last item selected in the ComboBox is
saved in a
textfile in the OnExit Event of the Mainform.
While loading the Mainform I want the text that was saved
in the file
to be compared with the items in the ComboBox ad get the
index of the
found item, so that I can set it as selected.

I thought i could do it something like this, but the
program hangs
before I can see anything.
---------
Code
---------
Dim i, As Integer
Dim line As String
For i = 0 To ComboBox1.Items.Count
If ComboBox1.Items(i) = line Then
IndexFound = i
Exit For
End If
Next
 
C

Cor Ligthert

Hi Niels,

The combobox.findstringexact is for that, that gives the index.

And remember that when you have an selectedindex change event in a combobox
or listbox that you have to stop working it with either a switch which you
set to true at the end of your complete loading of the combobox and bindings
or by removing the handlers and setting them at the right moment

I hope this helps?

Cor
 
H

Herfried K. Wagner [MVP]

* "Niels said:
I'm trying to get te index of a specific text in a
ComboBox.

See methods 'FindString' and 'FindStringExact' of the combobox control.
 
G

Guest

Thank you both for the quick reply, I have already tried
it and it worked perfect....



Thanks, Thanks, Thanks.......
 
C

Cor Ligthert

Hi Herfried,
See methods 'FindString' and 'FindStringExact' of the combobox control.

The OP has his answer, however

Once someone wrote to me that it was better to use the FindStringExact.

He told that you could find with the FindString not the exact one.

And you know how I am, I do not direct agree but I am cooperatieve and send
only that to this newsgroup, although I know that it is impossible to get
another result with the FindStringExact than the FindString in this case.

Do you know what did suprise me?

The same one who did send that message to me, was now sending (at almost the
same time as me) a message with the FindString.

:))

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
The OP has his answer, however

Once someone wrote to me that it was better to use the FindStringExact.

He told that you could find with the FindString not the exact one.

In my replies, I assume that the OP's F1 key is working...
And you know how I am, I do not direct agree but I am cooperatieve and send
only that to this newsgroup, although I know that it is impossible to get
another result with the FindStringExact than the FindString in this case.

Do you know what did suprise me?

The same one who did send that message to me, was now sending (at almost the
same time as me) a message with the FindString.

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top