2014-04-17 25 views
0

以下是我用於將DGV文本框單元格作爲自動完成文本框的代碼。爲什麼datagridview自動完成文本框背景顏色變黑?

private void dgvEntryVerify_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) 
     { 
      TextBox txtBox = e.Control as TextBox; 
      txtBox.CharacterCasing = CharacterCasing.Normal; 

      DataGridViewCell currentCell = dgvEntryVerify.CurrentCell; 
      List<string> tmpList = new List<string>(); 
      string tmpValue = ""; 

      try 
      { 

       if (e.Control is TextBox) 
       { 
        tmpValue = ""; 
        tmpList.Clear(); 

        TextBox currentTextBox = e.Control as TextBox; 
        currentTextBox.Multiline = false; 

        currentTextBox.AutoCompleteMode = AutoCompleteMode.Suggest; 
        currentTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource; 
        currentTextBox.AutoCompleteCustomSource = new AutoCompleteStringCollection(); 

        if (currentCell.OwningColumn.Name.Contains("Parish")) 
        { 
         tmpValue = ""; 
         tmpList.Clear(); 
         tmpValue = currentCell.EditedFormattedValue.ToString(); 
         tmpList = GlobalSettings.LookupParish.FindAll(t => t.StartsWith(tmpValue)); 
         if (tmpList.Count > 0) 
         { 
          currentTextBox.AutoCompleteCustomSource.AddRange(tmpList.ToArray()); 
         } 
        } 

       } 
      } 
      catch 
      { } 
     } 

但是在UI,自動完成的文本框變成黑色,我需要是白色的,這樣我可以看到我從列表中選擇相同的值。
enter image description here
任何解決方案,這是高度讚賞。

我正在使用VS2012,C#Winforms。

回答

0

黑色單元由一個代碼指定行在您的程序造成的:

tmpValue = currentCell.EditedFormattedValue.ToString(); 

我還沒有進一步看,爲什麼發生,因爲你不使用tmpValue可言,評論線,但將解決您的問題。