C#

DataGridView ComboBox editingcontrolshowing 이벤트 걸기

by kay posted Sep 04, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

참고 Url : http://stackoverflow.com/questions/6702729/datagridview-combobox-editingcontrolshowing-events


DataGridView에 이벤트를 걸고 해당 Row  및 Row의 특정 Column 지정하는 샘플 코드입니다.


// datagridView 에 이벤트 핸들러 추가
dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);



private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
	if (e.Control is ComboBox)
	{ 
		((ComboBox)e.Control).SelectionChangeCommitted -= new EventHandler(ComboBox_SelectedIndexChanged);
		((ComboBox)e.Control).SelectionChangeCommitted += new EventHandler(ComboBox_SelectedIndexChanged); 
	}
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
	ComboBox cmb = (ComboBox)sender;

	MessageBox.Show(dataGridView1.CurrentCell.RowIndex.ToString(),"");	// Row index 
	MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString(),"");  // 이벤트가 일어난 Row의 특정 Column (index or columnName )

	MessageBox.Show(((DataRowView)cmb.SelectedItem).Row.ItemArray[0].ToString(), "text");  // ComboBox Text 
	MessageBox.Show(((DataRowView)cmb.SelectedItem).Row.ItemArray[1].ToString(), "value");// ComboBox value 
}