2009-04-10 37 views

回答

0

是的,你可以用C#中的WinForms自动完成。以下是示例:

  1. 将文本框的AutoCompleteMode更改为SuggestAppend
  2. AutoCompleteSource更改为CustomSource

现在,写文本的Enter_Event下面的代码从任何表加载数据:

AutoCompleteStringCollection acs = new AutoCompleteStringCollection(); 
acs.Clear(); 

try 
{ 
    this.Cursor = Cursors.WaitCursor; 
    OleDbCommand odc = new OleDbCommand("<your sql statement>", <your connection>); 
    OleDbDataReader odr = odc.ExecuteReader(); 

    while (odr.Read()) 
    { 
     acs.Add(odr["name"].ToString()); 
    } 

    textbox1.AutoCompleteCustomSource = acs; 
} 
catch (Exception ex) 
{ 
    throw new ex; 
} 
finally 
{ 
    this.Cursor = Cursors.Default; 
} 

希望这个代码可以帮助。请回复其他任何疑问。