Reputation: 105
I have some problem when trying to get value of combobox in IF statement in Backgroundworker. When I try to run this code
if (KondisiSaldo.SelectedItem == "Kurang dari...")
{
view.RowFilter = string.Format("[Saldo] < '{0}'", thresholdcas);
view2.RowFilter = string.Format("[Saldo] > '{0}'", thresholdcas);
this.Invoke(new MethodInvoker(delegate
{
ViewDataSaldoGV.DataSource = view;
SaldoUnscheduleGV.DataSource = view2;
}));
}
The error says
Cross-thread operation not valid: Control 'KondisiSaldo' accessed from a thread other than the thread it was created on.
Can anyone help me ?
Upvotes: 1
Views: 75
Reputation: 148150
You are accessesing KondisiSaldo
in non GUI thread. Put the KondisiSaldo
in Invoke block to access it on GUI thread as your did with view
and view2
controls.
this.Invoke(new MethodInvoker(delegate
{
if (KondisiSaldo.SelectedItem == "Kurang dari...")
{
view.RowFilter = string.Format("[Saldo] < '{0}'", thresholdcas);
view2.RowFilter = string.Format("[Saldo] > '{0}'", thresholdcas);
ViewDataSaldoGV.DataSource = view;
SaldoUnscheduleGV.DataSource = view2;
}
}));
You may need to adjust the condition you have.
Upvotes: 4