Everyone must be familiar with the address bar of the IE browser. If you have no use, when you enter a string of characters, the drop-down list will list the first few characters and input characters that are stored in all historical records. .
We also need this technology in design programs to make it easy for users. What is it implemented?
Let me talk about how this effect I use CBuilder:
First create a new application, on the form, the name is set to: ComboBox1
Declaring a StringList in header files
Tstringlist * mydropdownlist;
The application initialization department stores all list data into mydropdownlist;
Add the following code to the keypress of ComboBoX1:
NT I, IinputLength, ISELSTARTRESTORE, ISELLENGTHRESTORE; ANSISTRING STRINPUT; TSTRINGLIST * TEMPLIST
Strinput = ComboBox1-> text;
IF (Key == VK_ESCAPE) {key = 0x0; // no more beeping after pressing escape.
IF (key == vk_return) {key = 0x0; if (ComboBox1-> items-> indexof (strinput) == -1) ComboBox1-> items-> add (strInput); comboBoX1-> DroppedDown = false;
ComboBox1-> SELSTART = ComboBox1-> text.length ();
} Else {iSelStartRestore = ComboBox1-> SelStart; iSelLengthRestore = ComboBox1-> SelLength; if (Key == VK_BACK) {// Handle backspace: if ((ComboBox1-> SelLength == 0) && (ComboBox1-> SelStart> 0) ) {ComboBoX1-> SELSTART = ComboBox1-> SELSTART - 1; ComboBoX1-> Sellength = ComboBox1-> Sellength 1;}} Strinput.delete (ComboBoX1-> SELSTART 1, ComboBox1-> sellength);
IF (key! = vk_back) {STRINPUT.INSERT (key, comboBox1-> selstart 1);} IinputLength = Strinput.Length (); ComboBox1-> items-> clear (); if (IINPUTLENGTH> 0) {
Templist = new tstringlist; try {for (i = 0; I
__finally {templist-> free ();}} else
ComboBOX1-> DroppedDown = false; // restore the position of the carrot and the selected text: ComboBox1-> selstart = iselstartRestore; ComboBox1-> selLength = iSellength;
}
Implementing C Builder Win2000, others should also.