Hello,
There are 2 issues when I tried adding data in datagridview when using backgroundworker,
1.The datagridview will freezing for a while like below:(Scrollbar cannot work)

The C# solution example:
private static object obj = new object();
private delegate void ChangeFunction(PackageMessage pm, string Message);
public void AddWarning(PackageMessage pm, string Message)
{
if (dgv.InvokeRequired)
{
ChangeFunction c = new ChangeFunction(AddWarning);
this.Invoke(c, new object[] { pm, Message });
}
else
{
lock (obj)
{
DataRow dr = MessageDT.NewRow();
dr[0] = pm.GetSendTime().ToString();
dr[1] = pm.GetSourceIP().ToString() + ":" + pm.GetSourcePort().ToString();
dr[2] = pm.GetDestinaionIP().ToString() + ":" + pm.GetDestinationPort().ToString();
dr[3] = Message;
MessageDT.Rows.Add(dr);
}
}
}
2.The datagridview sometimes will show a big red cross:

The C# solution example:
https://community.pega.com/knowledgebase/articles/pega-rpa/robotic-automation-example-correcting-datagridview-red-x-error
I just wondering is that possible to fix the 2 issues via maxscript code?Thanks in advance.
This is the example code:
rollout test_red_cross "Red Cross"
(
dotNetControl test_dgv "System.Windows.Forms.DataGridView" pos:[0,0] width:590 height:450
on test_red_cross open do
(
Red_title=dotNetObject "System.Windows.Forms.DataGridViewTextBoxColumn"
test_dgv.columns.add Red_title
Red_title.width=500
Fn Add_data=
(
for i=1 to 30 do test_red_cross.test_dgv.rows.add #(random 300 999)
)
test_backwork=dotnetobject "CSharpUtilities.SynchronizingBackgroundWorker"
test_backwork.WorkerReportsProgress=true
test_backwork.WorkerSupportsCancellation=true
dotNet.addEventHandler test_backwork "DoWork" Add_data
if not test_backwork.IsBusy do test_backwork.RunWorkerAsync()
)
)
CreateDialog test_red_cross 600 450