2010-03-10 17 views
3

我想創建一個winforms應用程序,您可以在其中爲實體分配標籤。我希望客戶重複使用現有標籤。這就是爲什麼我要 向他們展示的標籤列表,而他們正在打字(類似於智能感知在VS 和標籤,下拉菜單甚至在這裏計算器;))Winforms控件,像ajax標籤完成一樣工作

  • 你有任何的控制(S)介意提供這種功能?
  • 我可以重複使用ComboBox嗎? (這裏我需要編程砸下來 - 如何)

我想有標記列表獲取輸入焦點,但不輸MainForm的焦點, ,我想這是對所有窗口頂過去,甚至範圍外的主表區域 (如VS中的intellisense)

thx!

回答

1

這裏我已經做了一個函數,從哪個表中完成自動完成的表名,需要自動完成的字段的名稱以及需要作爲目標的組合框。

試試下面的代碼:

public void AutoCompleteTextBox(string tableName, string fieldName, ComboBox combToAutoComp) 
     { 
      AutoCompleteStringCollection txtCollection = new AutoCompleteStringCollection(); 
      DataTable dtAutoComp = Dal.ExecuteDataSetBySelect("Stored_Procedure", fieldName, tableName); 
      if (dtAutoComp.Rows.Count >= 0) 
      { 
       for (int count = 0; count < dtAutoComp.Rows.Count; count++) 
       { 
        txtCollection.Add(dtAutoComp.Rows[count][fieldName].ToString()); 
       } 
      } 
      combToAutoComp.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
      combToAutoComp.AutoCompleteSource = AutoCompleteSource.CustomSource; 
      combToAutoComp.AutoCompleteCustomSource = txtCollection; 
     } 

這裏Dal.ExecuteDataSetBySelect是我實現,其中我創建連接,命令和DataAdapter來調用存儲過程。你可以用你自己的實現替換它。欲瞭解更多請參考this link

+0

thx好友,工作充分。雖然我決定經過更多的努力,採取WPF陡峭的學習曲線,並從頭開始使用WPF的項目 - 祝我好運:) – Sargola 2010-04-07 21:34:32

+0

所有最好:) – HotTester 2010-04-08 07:35:25