試試這個。
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox nameComboBox = e.Control as ComboBox;
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
if (nameComboBox != null)
{
((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
nameComboBox .SelectedIndexChanged -= (nameComboBox _SelectedIndexChanged);
nameComboBox .SelectedIndexChanged += (nameComboBox _SelectedIndexChanged);
}
}
}
private void nameComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
var rowindex = dataGridView1.CurrentCell.RowIndex;
if (dataGridView1[1, rowindex].EditedFormattedValue != null)
{
Consol.WriteLine(dataGridView1[1, rowindex].EditedFormattedValue.ToString());
}
else
{
//No value in cell
}
}
}
我從字面上複製並粘貼了它,當我插入消息框進行測試時,它什麼也沒做。 –
基本上,我試圖從一個dataGridView移動到另一個dataGridView從一個組合框中選擇一個項目。那麼,有四個comboboxcolumns,但我想我只需要首先獲得一列的邏輯。 –
我道歉代碼沒有爲你做任何事情,但代碼將觸發,如果'細胞'是骯髒的這意味着你需要離開'細胞'來驗證你的名字,如果存在或不:) – spajce