日期:2014-05-19  浏览次数:20904 次

如何完成类似google,baidu搜索栏那样输入一个字,就能显示之前输入过的字呢?
如何完成类似google,baidu搜索栏那样输入一个字,就能显示之前输入过的字呢?
比如,之前输入过“中国”,下次我再输入“中”,就弹出个列表里面有   “中国”。
我想再winform中实现这个功能,不知道那位能详细介绍一下是如何完成的,最好有代码或者例子   。
呵呵   先   谢过   了   !!!

------解决方案--------------------
高级智能匹配下拉菜单控件:
http://faq.n90.cn/html/Net_jishu/zujian_kongjiankaifa/19990722/20452.html

------解决方案--------------------
在VS2005中这个问题变得很容易实现了,比如下面的代码设置了两个控件其中的某一种方式:

TextBox控件:

this.textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
this.textBox1.AutoCompleteSource = AutoCompleteSource.RecentlyUsedList;

ComboBox控件:
this.comboBox1.AutoCompleteMode = AutoCompleteMode.Append;
this.comboBox1.AutoCompleteSource = AutoCompleteSource.FileSystemDirectories;


------解决方案--------------------
WEB它是保存在Cookies中,WinForm你可以保存到XML或是文本中,你用第三方控件UltraCommbox之类的应该可以达到这种效果
------解决方案--------------------
如果在2003下的话,只能自己使用ComboBox来完成。
它要列出的列表,你需要使用文件或注册表等来保存起来。
写ComboBox的TextChanged事件来实时例出下拉列表。
你可以参考一下:http://blog.csdn.net/cocosoft/archive/2004/12/21/224278.aspx

如果在2005下的话,按上面的方法来做即可。
------解决方案--------------------
using System;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace CaseManager
{
/// <summary>
/// Summary description for ColumnComboBox.
/// </summary>
public class ColumnComboBox : ComboBox
{
private StringList m_slSuggestions = new StringList(); //A handy class used with the suggestion features.
private Keys m_kcLastKey = Keys.Space; //Last key pressed.
private int[] m_iaColWidths = new int[1];//Used for quick access to the column widths.
public uint ColumnSpacing = 4; //Minimum spacing between columns. Don 't go crazy with this...
private CCBColumnCollection m_Cols = new CCBColumnCollection();//A class used for managing the columns.

private DataTable m_dtData = null; //Main DataTable and DataView that contain the information to be shown in the ColumnComboBox.
private DataView m_dvView = null;

//private bool m_bShowHeadings = true; //Was going to do something with this but ran out of time.
private int m_iViewColumn = 0;//Which of the columns will be shown in the text box.
private bool m_bInitItems = true; //Flags used to determine when the things need to be initialized.
private bool m_bInitDisplay = true;
private bool m_bInitSuggestionList = true;

private bool m_bTextChangedInternal = false;//Used when the text is being changed by another member of the class.
public bool DropDownOnSuggestion = true;
public bool Suggest = true; //Suggesting can be turned on or off. No need for the whole property write out.
private int m_iSelectedIndex = -1; //Used for storing the selected index without depending on the base.

private System.ComponentModel.Container components = null;

public ColumnComboBox()
{
if(components == null)
components = null;
Data = new DataTable(); //Make sure the DataTable is not blank
Init();

}
public ColumnComboBox(DataTable dtData)
{
Data = dtData;
Init();
}
private void Init()
{
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
}