开发者

DataGridViewComboBoxCell - needs 2 clicks to get the current selected index

I have this code :

private void vicationDataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (zawag) {
                ComboBox cbo = e.Control as ComboBox;
                if (cbo != null)
                {
              开发者_Python百科      if (cbo.SelectedIndex == 6)
                    {
                        MessageBox.Show("test");
                    }
                }

            }
        }

When I run my app, this code will not work untill I click the combobox 2 times and sometimes 3 clicks, I need to let it work for the first click when the user select value for the first time.

I tried to set the EditMode to EditOnEnter but the problem is not solved.


You need to use your DataGridView's EditingControlShowing event to add an event handler for the SelectedIndexChanged event of the ComboBox in your grid. You can move the code you have for testing the ComboBox's SelectedIndex to the method that's invoked when the SelectedIndexChanged event fires.

There's a great example in MSDN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜