Abdul Asif

Abdul Asif

  • NA
  • 27
  • 0

How to Add into DataGrid Dynamically

Oct 23 2007 2:34 PM

Hi All,

I am trying to add data into grid but it doesn't work me. Please can anyone take a look my code and tell me what am doing wrong.

Thanks,


//This data grid has two columns and initially has one row

int countVisitorVarRows = 0;

someforLoop
{
if (newVisitorVarRow == true)
{
   countVisitorVarRows++;
   dataGridView1.Rows.Add(); //adding second row
   dataGridView1.Rows[countVisitorVarRows].Cells[0].Value = str4[i]; //get error here outBound index
   dataGridView1.Rows[countVisitorVarRows].Cells[1].Value = str3[i]; //get error here outBound index

  
}

if (newVisitorVarRow  == false)
{
   dataGridView1.Rows[0].Cells[0].Value = str4[1]; //Inserting value in first row
   dataGridView1.Rows[0].Cells[1].Value = str3[1]; //Inserting value in first row

   newVisitorVarRow = true; //if true add new rows
}

} //ENd of someforLoop()


Answers (1)