C# dataGridView\u CellContentClick:无法对控件调用Invoke或BeginInvoke
有人能告诉我我做错了什么吗这段代码,它产生了味精 “在创建窗口句柄之前,无法对控件调用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) {
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);
}