BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TComboBox->ItemIndex not keeping value

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
William Charles Nickerson
Guest





PostPosted: Thu Jun 24, 2004 7:40 pm    Post subject: TComboBox->ItemIndex not keeping value Reply with quote



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





PostPosted: Thu Jun 24, 2004 8:05 pm    Post subject: Re: TComboBox->ItemIndex not keeping value Reply with quote




"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





PostPosted: Thu Jun 24, 2004 8:58 pm    Post subject: Re: TComboBox->ItemIndex not keeping value Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.