Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dataGridView\u CellContentClick:无法对控件调用Invoke或BeginInvoke_C# - Fatal编程技术网

C# dataGridView\u CellContentClick:无法对控件调用Invoke或BeginInvoke

C# dataGridView\u CellContentClick:无法对控件调用Invoke或BeginInvoke,c#,C#,有人能告诉我我做错了什么吗这段代码,它产生了味精 “在创建窗口句柄之前,无法对控件调用Invoke或BeginInvoke。” private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == buyColumn.Index) {

有人能告诉我我做错了什么吗这段代码,它产生了味精

“在创建窗口句柄之前,无法对控件调用Invoke或BeginInvoke。”

private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

                if (e.ColumnIndex == buyColumn.Index)
                {

                    double openprice = (double)dataGridView.Rows[e.RowIndex].Cells[offerColumn.Index].Value;
                    string symbol = dataGridView.Rows[e.RowIndex].Cells[symbolColumn.Index].Value.ToString();
                    double quanity= (double)dataGridView.Rows[e.RowIndex].Cells[quanityColumn.Index].Value;

                    MessageBox.Show("I buy " + symbol +  " with "  + quanity + " at " + openprice);
            }        
更新:调试后,这3行导致问题,请告诉我如何修复

double openprice = (double)dataGridView.Rows[e.RowIndex].Cells[offerColumn.Index].Value;
                        string symbol = dataGridView.Rows[e.RowIndex].Cells[symbolColumn.Index].Value.ToString();
                        double quanity= (double)dataGridView.Rows[e.RowIndex].Cells[quanityColumn.Index].Value;
试一试


不可用,没有开始/调用的迹象,决不应在单击事件上发生。发布异常的堆栈跟踪。
        if (dataGridView.IsHandleCreated && e.ColumnIndex == buyColumn.Index)
        {

            double openprice = (double)dataGridView.Rows[e.RowIndex].Cells[offerColumn.Index].Value;
            string symbol = dataGridView.Rows[e.RowIndex].Cells[symbolColumn.Index].Value.ToString();
            double quanity= (double)dataGridView.Rows[e.RowIndex].Cells[quanityColumn.Index].Value;

            MessageBox.Show("I buy " + symbol +  " with "  + quanity + " at " + openprice);
         }