Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a datagridveiw combo box with a few values in there. I am trying to capture what user clicked. I tried CellValueChanged, CellContentClicked etc. but nothing works.
I want to store this value to a variable (important) and then shift the cursor to Column after user has selected value.

Please help. Please also advise what event to fire.

Thanks
Posted

In stead of trying CellValueChanged, you can use the below code
C#
dataGridView1.Rows["YourRowNumber"].Cells["YourColumnNameOrNumber"].Value;


It fetches the selected value properly.
 
Share this answer
 
Comments
sahabiswarup 10-Jan-12 3:05am    
good job
Furqan Sehgal 10-Jan-12 3:08am    
But in what event?
Ganesan Senthilvel 10-Jan-12 3:15am    
EditingControlShowing of DataGridView. Sample code is attached. Not sure why the answer is marked as -16
Furqan Sehgal 10-Jan-12 3:22am    
I put it like this in your given event, when I clicked on four in my combo, no response
If dg.Rows(0).Cells(0).Value = "Four" Then
MsgBox("Success")
End If
On DataGrid EditingControlShowing event,

C#
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    try
    {
        if (this.dataGridView.CurrentCell.ColumnIndex == (int)Column.Col)
        {
            ComboBox comboBox = e.Control as ComboBox;
            if (comboBox != null)
            {
                comboBox.SelectedIndexChanged += new EventHandler(ComboBoxIndexChanged);
            }
        }
        return;
    }
}

private void ComboBoxIndexChanged(object sender, EventArgs e)
{
    dataGridView1.Rows["YourRowNumber"].Cells["YourColumnNameOrNumber"].Value;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900