| View previous topic :: View next topic |
| Author |
Message |
William Charles Nickerson Guest
|
Posted: Thu Jun 24, 2004 7:40 pm Post subject: TComboBox->ItemIndex not keeping value |
|
|
Hello
I have a TComboBox. I don't want to use AutoComplete as the user needs to
be able to enter a new value into the edit. However, if they type an
existing item I want it to be selected.
In the OnChange handler I check to see if the item is in the list (using
Items->IndexOf ()) and if so, I set ItemIndex to the selected index. During
debugging I see this happening correctly.
The dialog also has an OK button. The code for this checks the ItemIndex
property of the TComboBox and finds that it is now -1. If I select the item
from the list the value is okay. If I enter the value in the edit box and
then popup the pulldown (without actually clicking on an entry), I see the
entry selected and the ItemIndex value is fine when I click on OK.
What am I missing here?
Aloha
Bill
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Thu Jun 24, 2004 8:05 pm Post subject: Re: TComboBox->ItemIndex not keeping value |
|
|
"William Charles Nickerson" <bill (AT) wcnickerson (DOT) ca> wrote:
| Quote: | [...] The dialog also has an OK button. The code for this
checks the ItemIndex property of the TComboBox and finds
that it is now -1.
|
I can't explain why it's happening without actually seeing
your code and even then ... but I can offer a solution.
You can still implement your own Auto Complete with out
setting the ItemIndex directly so don't do it. Use the index
that you have already to grab the Items->Strings[] and use it
to complete the Text, setting the SelStart and SelLength in
the process.
Then in the OKButtonClick, use the ComboBox's Text and IndexOf
method:
if( ComboBox1->Items->IndexOf(ComboBox1->Text) < 0 )
{
// it's not in the list
}
~ JD
|
|
| Back to top |
|
 |
William Charles Nickerson Guest
|
Posted: Thu Jun 24, 2004 8:58 pm Post subject: Re: TComboBox->ItemIndex not keeping value |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote
| Quote: |
"William Charles Nickerson" <bill (AT) wcnickerson (DOT) ca> wrote:
[...] The dialog also has an OK button. The code for this
checks the ItemIndex property of the TComboBox and finds
that it is now -1.
I can't explain why it's happening without actually seeing
your code and even then ... but I can offer a solution.
You can still implement your own Auto Complete with out
setting the ItemIndex directly so don't do it. Use the index
that you have already to grab the Items->Strings[] and use it
to complete the Text, setting the SelStart and SelLength in
the process.
Then in the OKButtonClick, use the ComboBox's Text and IndexOf
method:
if( ComboBox1->Items->IndexOf(ComboBox1->Text) < 0 )
{
// it's not in the list
}
~ JD
Thanks JD |
I don't want it to AutoComplete at all, but using the IndexOf () in the OK
button would work around the problem I'm having, so I'll give it a try. I'd
still be interested in knowing why the ItemIndex is being reset though.
Ciao
Bill
|
|
| Back to top |
|
 |
|