开发者

dataGridView_CellContentClick: Invoke or BeginInvoke cannot be called on a control

Can any one show me what did i do wrong this code, it produce msg

“Invoke or BeginInvoke cannot be called on a control until the window handle ha开发者_如何学运维s been created.”

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);
            }        

Update: after debug , these 3 lines cause the issues , plz show me how to fix

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;


Try

        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);
         } 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜