 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lance Robaldo Guest
|
Posted: Wed Nov 26, 2003 8:06 pm Post subject: TComboBox with Typing |
|
|
I'm looking for a way to have a TComboBox do an incremental search much like
the way it does if you set it's style to "DropDownList".
However, I don't want to restrict the user to ONLY typing what's in the
list.
Is there any way around this?
Thank you,
Lance Robaldo
[email]Lance (AT) Robaldo (DOT) com[/email]
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Thu Nov 27, 2003 11:05 am Post subject: Re: TComboBox with Typing |
|
|
"Lance Robaldo" <RRobaldo (AT) wltsoftware (DOT) com> wrote:
| Quote: | I'm looking for a way to have a TComboBox do an incremental
search much like the way it does if you set it's style
to "DropDownList".
|
Set it's AutoComplete property to true. If your version
doesn't have an AutoComplete property, have a look here:
http://www.torry.net/enhancedlistandcomboboxes.htm
If you don't want to use a 3rd party component, you can mimic
the same behavior using the OnKeyPress event. Performance may
become an issue however if the number of items gets too large
(untested):
void __fastcall TForm1::ComboBox1KeyPress(TObject* Sender, char &Key)
{
TComboBox* CB = static_cast<TComboBox*>( Sender );
int size = CB->GetTextLen() + 2;
char* Buf = new char[ size ];
strcpy( Buf, CB->Text.c_str() );
CB->SelLength = 0;
int curpos = CB->SelStart;
Buf[ curpos ] = Key;
Buf[ curpos + 1 ] = 0;
int Index = 0;
if( CB->ItemIndex > -1 )
{
if( strncmp( Buf, CB->Items->Strings[ CB->ItemIndex ].c_str(), strlen( Buf ) - 1 ) <= 0 )
Index = CB->ItemIndex;
}
for( int x = Index; x < CB->Items->Count; ++x )
{
int Result = strncmp( Buf, CB->Items->Strings[ x ].c_str(), strlen( Buf ) );
if( Result == 0 )
{
Index = x;
break;
}
else if( Result > 0 )
{
Index = -1;
break;
}
}
CB->ItemIndex = Index;
if( Index > -1 )
{
CB->Text = CB->Items->Strings[ Index ];
CB->SelStart = curpos + 1;
CB->SelLength = CB->GetTextLen() - CB->SelStart;
Key = 0;
}
delete [] Buf;
}
~ JD
|
|
| Back to top |
|
 |
|
|
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
|
|