關於ListBox |
答題得分者是:axsoft
|
sb055665
一般會員 發表:24 回覆:25 積分:14 註冊:2006-07-12 發送簡訊給我 |
|
sb055665
一般會員 發表:24 回覆:25 積分:14 註冊:2006-07-12 發送簡訊給我 |
|
axsoft
版主 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
AutoComplete 資料來源: http://www.dallastech.com/Index.html Internet Explorer and other Microsoft products feature ComboBoxes that allow the user to type in partial strings and the control automatically completes those strings that match the contents of the drop down list. This is not really a new feature, just a new way to use the existing ComboBox. This example will demonstrate how to perform autocompletion of strings using Borland C Builder. The techniques employed here apply equally to MFC applications written in Microsoft VisualC . Create a new project (File|New|Application). Place a checkbox on the default form. You should have something that looks like this: Load the strings into the ComboBox drop down list. You can do this at design time from within the IDE or at runtime. This example will utilize runtime loading. Place the following code in the main form constructor. Feel free to change the strings as you like: ComboBox->Items->Clear(); ComboBox->Items->Add("__int64"); ComboBox->Items->Add("bool"); ComboBox->Items->Add("char"); ComboBox->Items->Add("double"); ComboBox->Items->Add("float"); ComboBox->Items->Add("int"); ComboBox->Items->Add("long"); ComboBox->Items->Add("short"); ComboBox->Items->Add("wchar_t"); Add the following code to the ComboBox OnKeyDown event. The purpose here is to remember the index into the string array for the currently selected item in the drop down list. The Tag property of the ComboBox is a convenient place to store the index. Tag is defined to be an int, as is the index into the string array. // Store the last key the user pressed in the "Tag" property of the // TComboBox instance TComboBox *CB = dynamic_cast Now add the following code to the ComboBox OnChange event processor. This event will fire every time the ComboBox contents is changed - on every key stroke. Note that it takes into account the possibility that the user might type a backspace (0x08) or a delete key. The call to Perform invokes the ComboBox FindString function. This is preferable to using the VCL string array search function. It's a bit faster. TComboBox *CB = dynamic_cast Compile the application and check out the results. With version 6 of C Builder, this functionality is integrated with the TCustomComboBox class and its descendents. So there is really no need to implement the code in this example. Simply set the AutoComplete property to true. However, if you are using an older version or Microsoft Visual C , you will have to do it the hard way.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |