0

I have a DataSet that contains values returned by my WCF function, as below:

DataSet ds = IserviceClient.FunctionMe(dcClient, dcBook);

#region show to dgv_item
DataTable dt1 = ds.Tables[0];
DataRow dr1;
int rc = dt1.Rows.Count;
clsMessageBoxes.ShowInfo(rc.ToString()); // Here show the number of row, so far the row is show the right value

//from here how to pass the row in that datatable to my datagridview? i 
for (int i = 0; i < rc; i++)
{                    
   dr1 = dt1.Rows[i];

   dgv_item.Rows.Add();
   dgv_item.Rows[i].Cells["dgvc_no"].Value = dr1["cnNo"].ToString();
   dgv_item.Rows[i].Cells["dgvc_ID"].Value = dr1["cnID"].ToString();
   dgv_item.Rows[i].Cells["dgvc_Name"].Value = dr1["cnName"].ToString();
}

Using this, I get the error

Rows cannot be programmatically added to datagridview's rows collection when the control is data-bound

Why do I get this, and how can I resolve it?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Ke Vin
  • 3,478
  • 11
  • 60
  • 91
  • why dont you pass from dataTable to gridview? gridview1.datasource=dt1; gridview1.databind(); – zxc Nov 07 '13 at 00:46
  • @zxc i already have bind the datagridview.datasource=dt1 in designer – Ke Vin Nov 07 '13 at 00:57
  • so what you needed is to append the rows to the existing data in gridview? – zxc Nov 07 '13 at 01:06
  • maybe you can do something like this http://stackoverflow.com/questions/15965043/how-to-add-rows-to-datagridview-winforms – zxc Nov 07 '13 at 01:08

0 Answers0