나는 콤보 박스가있는 DataGridview를 가지고있다.DataGridViewComboboxColumn SelectedIndex keypress 이벤트를 얻는 방법?
나는 다음 코드를 사용하여 콤보 상자의 선택된 인덱스를 얻을 수 있습니다 :
private void dg_errorchart_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
if (e.Control is DataGridViewComboBoxEditingControl)
{
((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
}
ComboBox cmbBx = e.Control as ComboBox;
if (e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl))
{
ComboBox comboBoxCell = (ComboBox)e.Control;
if (comboBoxCell != null)
{
comboBoxCell.SelectionChangeCommitted -= new EventHandler(comboBoxCell_SelectionChangeCommitted);
comboBoxCell.SelectionChangeCommitted += new EventHandler(comboBoxCell_SelectionChangeCommitted);
}
}
}
catch (Exception ex)
{
}
}
그러나 문제는이 키보드에 의해 선택되어있는 경우 나 콤보 상자의 인덱스를 얻을 수있다. 어떻게해야합니까?
는 UPDATE :
난 그냥 콤보 및 캐치 수동으로 입력하고 행 ID를 높이기 위해 또 다른 이벤트 처리기를 추가했다.
cmbBx.KeyUp -= new KeyEventHandler(cmbBx_KeyUp);
cmbBx.KeyUp += new KeyEventHandler(cmbBx_KeyUp);
과 내가 추가 한 이벤트 처리기에서
:DataGridViewCell currentCell = dg_errorchart.CurrentCell;
if (currentCell != null)
{
DataGridViewComboBoxEditingControl cmbBx = sender as DataGridViewComboBoxEditingControl;
if (cmbBx.SelectedIndex >= 0)
{
int nextRow = 0;
nextRow = currentCell.RowIndex + 1;
if (nextRow >= dg_errorchart.Rows.Count)
{
nextRow = nextRow - 1;
}
DataGridViewCell nextCell = dg_errorchart.Rows[nextRow].Cells[6];
dg_errorchart.CurrentCell = nextCell;
}
}
감사
Suressh
변경 내용이 커밋되지 않았기 때문에 컨트롤에서 'Tab'키를 누르면 작동합니까? – V4Vendetta