2013-12-09 47 views
2

我正在使用Datagridview,部分由數據源填充,通過設置DataPropertyNames。 部分由我代碼填寫。 我有一個DataGridViewComboBoxColumn,其中單元格應該填充時,我點擊旁邊的按鈕。 單擊按鈕填充DataGridViewComboBoxCell的項目,但如果我單擊ComboBox,我無法打開它來選擇一個值。DataGridViewComboBoxCell中的新項目不顯示

(在函數結束時,我改變columnvalue以X作爲測試,能正常工作......)

代碼:

//add the combobox column 
DataGridViewComboBoxColumn cellcol = new DataGridViewComboBoxColumn(); 
cellcol.Name = "Cell"; 
cellcol.ReadOnly = false; 
dataGridView1.Columns.Add(cellcol); 

//method that gets called when the button is clicked 
private void getAllCells(List<ComponentRow> componentRows, int i) 
     { 

      //show all cells 
      CellFilter cf = new CellFilter(); 
      cf.customerNr = libraryNr; 
      Cell[] cells = Service.Instance.Client.queryCells(cf, new QueryParam()); 
      foreach (Cell c in cells) 
      { 
       ((DataGridViewComboBoxCell)dataGridView1["Cell", i]).Items.Add(cells[0].cell_name); 
      } 
      cellsShownForComponents[i] = ShowedCells.ALL; 
      ((DataGridViewTextBoxCell)dataGridView1["variants", i]).Value = "x"; 
     } 
+0

*如果我點擊在組合框上,我無法打開它來選擇一個值* - >這意味着組合框根本沒有任何項目,也可能需要點擊組合框兩次,第一個是激活它,第二個是ac真的要放下它的名單。 –

+0

組合框包含項目(我已通過調試進行檢查)。點擊兩次也不起作用。我確實在datagridview上實現了點擊事件處理程序,但由於它對其他單元格仍然是正常的,所以我不明白爲什麼它對於combobox列 – RazorEater

回答

2

我會回答我的問題。問題是我的datagridview是隻讀的。只讀comboboxcolumns無法打開。 我固定它是這樣的: 的datagridview的

ReadOnly = false 

我comboboxcolumn

ReadOnly = false 

每隔列用戶不應該能夠編輯

ReadOnly = true 
+0

感覺不正常!在我玩耍的時候保存了我的一天,並開始嗅到EF6的味道。隊友的歡呼聲! –