I have to write values to datagridview Column 2 which is in Form2(Form2 called in Mainform).
but I to want fill coloum2 rows from thread(required).
I have used delegate to avoid cross thread operation
but the datagridview1 rows count is always 1 in threadclass and on form2 it shows right count.
why datagridview1 shows one count always.
I don't know where the problem is
// Form 2 is called in MainForm
Form2
In form 2 there is button which is used to dynamicaly add rows in gridview
Datagridview1.Rows.Add(Convert.ToInt32(textbox1.Text));
// and I fill Sr.no colum by following code e.g 1,2,3
for (int i = 0, j = 1; i <= Datagridview1.RowCount-1 ; j++, i++)
{
Datagridview1.Rows[i].Cells[0].Value = (j).ToString();
}
//this is done to handle error; bool variable
Form2HandleCreated= true;</pre>
ThreadClass
My thread class objects starts in InitialStartup Form
//this delegate is used to write values to datagrivew which is in form2
public delegate void Del_WriteValueToGridView(int count, string Value);
if (Form2HandleCreated== true)
{
for (int i = 0; i <= 10; i++)
{
SR = i;
Value= i.ToString();
Program.Form2Obj.TopLevel = true;
Program.MainFormObj.Labe11.Invoke(new Del_WriteValueToGridView(WriteToGridView), SR, Value);
if (i > 10) ;
Form2HandleCreated = false;
}
void WriteToGridView(int count,string Value)
{
int n= Program.Form2Obj.DataGridView1.Rows.Count;
Program.Form2Obj.DataGridView1.Rows[count].Cells[1].Value = Value;
}