开发者

dataGridView_CellContentClick: Invoke or BeginInvoke cannot be called on a control

开发者 https://www.devze.com 2023-02-13 20:28 出处:网络
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.”

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

精彩评论

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