void __fastcall TMainForm::ComboBoxTitleKeyPress(TObject *Sender, wchar_t &Key)
{
m_bTitlSearchFlag = true;
int i, iInputLength, iSelStartRestore, iSelLengthRestore;
AnsiString strInput;
TStringList *TempList;
strInput= ComboBoxTitle->Text;
if (Key == VK_ESCAPE)
{
Key = 0x0; // No more beeping after pressing Escape.
}
if (Key == VK_RETURN)
{
Key = 0x0;
}
if (ComboBoxTitle->Items->IndexOf(strInput) == -1)
{
ComboBoxTitle->Items->Add(strInput);
ComboBoxTitle->DroppedDown = false;
ComboBoxTitle->SelStart = ComboBoxTitle->Text.Length();
}
else
{
iSelStartRestore = ComboBoxTitle->SelStart;
iSelLengthRestore = ComboBoxTitle->SelLength;
if (Key == VK_BACK)
{
// Handle backspace:
if ((ComboBoxTitle->SelLength == 0) && (ComboBoxTitle->SelStart > 0))
{
ComboBoxTitle->SelStart = ComboBoxTitle->SelStart - 1;
ComboBoxTitle->SelLength = ComboBoxTitle->SelLength + 1;
}
}
strInput.Delete(ComboBoxTitle->SelStart + 1, ComboBoxTitle->SelLength);
if (Key != VK_BACK)
{
strInput.Insert(Key, ComboBoxTitle->SelStart + 1);
}
iInputLength = strInput.Length();
ComboBoxTitle->Items->Clear();
if (iInputLength > 0)
{
TempList = new TStringList;
try
{
for ( i= 0; i<m_pTitleDropDownTStrList->Count - 1;i++)
{
if ((m_pTitleDropDownTStrList->Strings[i].SubString(1, iInputLength)).UpperCase() ==
strInput.UpperCase())
TempList->Add(m_pTitleDropDownTStrList->Strings[i]);
}
if (TempList->Count > 0)
{
ComboBoxTitle->Items->Clear();
for (i = 0 ;i<7;i++)
{
ComboBoxTitle->Items->Add("AAA");
}
//ComboBoxTitle->DropDownCount = 8;
ComboBoxTitle->DroppedDown = true;
//ComboBoxTitle->Items->Clear();
ComboBoxTitle->Items = TempList;
}
else ComboBoxTitle->DroppedDown = false;
}
__finally
{
TempList->Free();
}
}
else
{
ComboBoxTitle->DroppedDown = false;
}
//ComboBoxTitle->Re
// Restore the position of the carrot and the selected text:
ComboBoxTitle->SelStart = iSelStartRestore;
ComboBoxTitle->SelLength= iSelLengthRestore;
}
m_bTitlSearchFlag = false;
}