2014-10-12 107 views
0

我想使用充滿數據集的外部物理組合框。當我進入該單元格時,我希望該組合框在特定單元格地址的網格中可用。導航應該用鍵盤。在此先感謝datagridview中的可移動組合框

我使用以下代碼,但它不可用在單元格中輸入&也鍵盤導航無法正常工作。 1- Formload datagridview1.Controls.Add(conbobox1);

2節開始編輯

private void datagridview1_CellBeginEdit(object sender, 
             DataGridViewCellCancelEventArgs e) 
{ 
    if (datagridview1.CurrentCell.ColumnIndex == 16) 
    { 
     conbobox1.Visible = true; 
     conbobox1.Size = datagridview1.CurrentCell.Size; 
     conbobox1.Location = datagridview1.GetCellDisplayRectangle(
              e.ColumnIndex, e.RowIndex, true).Location; 
    } 
} 

回答

0

DataGridComboBoxColumn添加DataGridComboBoxCell。我爲你寫了一個例子(全部是代碼):

DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn(); 
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); 
cell.Items.Add("Sth1"); 
cell.Items.Add("Sth2"); 
DataGridViewRow row = new DataGridViewRow(); 

if (dataGridView1.Columns.Count == 0) 
    dataGridView1.Columns.Add(col); 
row.Cells.Add(cell); 
dataGridView1.Rows.Add(row); 

但是你可以在設計時添加該列。

+0

是使用我寫的代碼的任何可能的解決方案。 – Ranjeet 2014-10-15 07:34:00

+0

你不能把'System.Windows.Form.ComboBox'放在'Datagridview'中 – 2014-10-15 08:04:27

+0

我想讓DataGridViewComboBoxColumn像DropDown一樣工作,不像DropDownlist。 – Ranjeet 2014-10-15 13:04:22