| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                            Tags
                            
                        
                          
                          - Eclipse
 - Linux
 - geckodriver
 - SCADA
 - STS
 - DataTables
 - Custom
 - build
 - JQuery
 - LOG
 - ORA-28002
 - 명령어
 - 말라키
 - 리눅스
 - 원한
 - 분노
 - Python
 - 가상환경
 - HMI
 - 파이썬
 - 맥코트
 - error
 - checkbox
 - Anaconda
 - pythoncom37.dll
 
                            Archives
                            
                        
                          
                          - Today
 
- Total
 
2010년 5월 1일, 2막
[C#] what event catches a change of value in a combobox in a DataGridViewCell? 본문
      Computer
      
    [C#] what event catches a change of value in a combobox in a DataGridViewCell?
창천(蒼天) 2013. 4. 21. 22:15DataGridView에 combobox cell을 추가한 상태에서 combobox의 값이 변경될 때 발생하는 이벤트 확인법
I want to handle the event when a value is changed in a  ComboBox in a DataGridView cell. Theres the CellValueChanged event but that one doesn't fire until i click somewhere else inside the DataGridView. A simple ComboBox SelectedValueChanged does fire immidialy after a new value is selected. How can i add a listener to the combobox thats inside the cell ?
Thank you.
This is the code, which will fire the event of the selection in the comboBox in the dataGridView:
public Form1()
    {
        InitializeComponent();
        DataGridViewComboBoxColumn cmbcolumn = new DataGridViewComboBoxColumn();
        cmbcolumn.Name = "cmbColumn";
        cmbcolumn.HeaderText = "combobox column";
        cmbcolumn.Items.AddRange(new string[] { "aa", "ac", "aacc" });
        dataGridView1.Columns.Add(cmbcolumn);
        dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);
    }
    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        ComboBox combo = e.Control as ComboBox;
        if (combo != null)
        {
            combo.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged);
            combo.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);
        }
    }
    private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        ComboBox cb = (ComboBox)sender;
        string item = cb.Text;
        if (item != null)
            MessageBox.Show(item);
    }
'Computer' 카테고리의 다른 글
| [C#] assigning Null value to datetime in C# (0) | 2013.05.09 | 
|---|---|
| [C#] BackgroundWorker (0) | 2013.04.26 | 
| [C#] Query문을 내가 작성할 경우 (0) | 2013.04.19 | 
| [Tip] 부팅때마다 CHKDSK 디스크 검사를 반복할 때 해결방법 디스크 검사 없애기 (4) | 2013.04.18 | 
| RAID CLI tool 사용법 (0) | 2013.04.16 |