2014-12-03 86 views
0

我有一個組合框,它定義了屏幕上其他框的內容。下拉框,當按下一個鍵時,跳轉到選擇

因此,例如,如果我要在我的組合框中輸入員工姓名的「Apple」,則會導致錯誤,因爲我的數據庫中沒有「Apple」員工,這意味着無法檢索到填充表格的其餘部分。

是否有我可以設置的屬性或代碼片段我可以編寫以確保用戶在組合框中鍵入的任何內容將突出顯示從該繪圖中選擇的內容?

回答

0

您可以將DropDownStyle設置爲DropDownList(而不是DropDown)。然後用戶可以繼續輸入,但Combobox僅在存在此類元素時才切換選擇。

(然而,這確實改變了組合框,Appearence,所以它看起來不再像「FreeText的」可用)

設置AutoCompleteModeSuggestAutoCompleteSourceListItems爲了讓多隻的第一個字母輸入更多的文字。 (組合框將擴大和更多的字母切換元件作爲用戶類型。)

0

檢查數據源(數據表,數據集等等等等)的計所綁定到組合框

if(DataSource!=null && DataSource.rows.count>0) 
{ 
    combobox.datasource=DataSource; 
    combobox.refresh(); 
} 
0

我會建議你做以下事情:

1.拿一個文本框,並設置文本框的屬性爲 AutoCompleteMode=SuggestAppendAutoCompleteSource = CustomSource

2.在數據表(可能是員工名稱或您想要的任何其他列)中載入您想要的值。

3.在您的頁面加載或任何您想要的事件中調用以下方法。

public bool AutoComplete() 
{ 
    try 
    { 
     DataTable dtEmpName=/////// store the employees name in this DataTable. 
     var empNames = dtEmpName.Select(s => s.EmpName('the column you want').Distinct().ToArray(); 
     /////// Auto complete Name from Surname 
     AutoCompleteStringCollection instcol = new AutoCompleteStringCollection(); 
     instcol.AddRange(empNames); 
     txtEmpNames.AutoCompleteCustomSource = instcol; 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 
相關問題