Reputation: 784
i am using c# and when i try to fill my datagridView most of the time a big red cross apears.
i searched for this and people say that you have to add
public class SafeDataGridView : DataGridView
{
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
try
{
base.OnPaint(e);
}
catch (Exception)
{
this.Invalidate();
}
}
}
i tried to just add this in a simple class file but that did not do anything.
Upvotes: 2
Views: 5061
Reputation: 7150
Same question here. Use Invoke method
if (gridView.InvokeRequired)
gridView.Invoke(new MethodInvoker(() => gridView.DataSource = YOUR_DATASOURCE));
else
gridView.DataSource = YOUR_DATASOURCE;
Upvotes: 0
Reputation: 352
In YourForm.Designer.cs look for string gridView = new DataGridView()
and replace it with
gridView = new SafeDataGridView()
private SafeDataGridView portos_online;
portos_online = new SafeDataGridView();
I hope this will solve your problem. Have a nice day!
Upvotes: 2