Merci Robert
Voici ce que je fais
Le process appelé contient deux boucles imbriquées qui remplissent une datatable de n x n
J'ai deux event : 1 pour l'ajout de row, 1 pour l'ajout de cellule
L'event ajout de cellule affiche un compteut dans la form appellante
L'event ajout de row fait un refresh du dgv qui possede la datatable en datasource
Voci la partie du code dans la form appellante
DistMatrix dm = new DistMatrix();
dm.VV = VV;
dm.AddRow += new DistMatrix.StepRowDelegateHandler(Dist_StepRow);
dm.AddCell += new DistMatrix.StepCellDelegateHandler(Dist_StepCell);
ThreadPool.QueueUserWorkItem(new WaitCallback(Process), dm);
}
public delegate void StepCellDelegateHandler(int a, int b);
public delegate void StepRowDelegateHandler(DataTable dt);
// *****************************************************************************************
void Process(Object DM)
{
DataTable dtn = ((DistMatrix)DM).getMatrix(dtAdr);
}
// *****************************************************************************************
private void Dist_StepCell(int a, int b)
{
if (this.InvokeRequired)
{
try
{
this.Invoke(new StepCellDelegateHandler(StepCell), new object[] { a, b });
return;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
else
{
this.StepCell(a, b);
}
}
// *****************************************************************************************
private void StepCell(int X, int Y)
{
if (X == -1)
{
MessageBox.Show("Call -1");
btn_print.Enabled = true;
btn_export.Enabled = true;
toolStrip1.Enabled = true;
return;
}
lbl_Progress.Text = string.Format("{0}-{1} / {2}", Y, X, dtAdr.Rows.Count);
lbl_Progress.Refresh();
}
// *****************************************************************************************
private void Dist_StepRow(DataTable dt)
{
if (this.InvokeRequired)
{
try
{
this.Invoke(new StepRowDelegateHandler(AddRow), new object[] { dt });
return;
}
catch (Exception e)
{
MessageBox.Show("Row:" + e.Message);
}
}
else
{
this.AddRow(dt);
}
}
// *****************************************************************************************
private void AddRow(DataTable Dt)
{
if (dgv_Dist.DataSource == null)
{
dgv_Dist.DataSource = Dt;
foreach (DataGridViewColumn dgvc in dgv_Dist.Columns)
{
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Format = "N2";
style.Alignment = DataGridViewContentAlignment.MiddleRight;
dgvc.DefaultCellStyle = style;
}
}
dgv_Dist.Refresh();
}