Hi all,
Please solve my Problem:
I have DataGridView and Dataset. I want to add data from dataset to datagridview row by row and not by using DataGridView.DataSource method.
For ex. following is the way to do the same using Vb.net
dgClient.Columns.Add("client", "Client")
dgClient.Columns("client").Width = 150
dgClient.Columns.Add("comments", "Comments")
dgClient.Columns("comments").Width = 250
Dim i As Integer
For i = 0 To dsClient.Tables("TableClient").Rows.Count - 1
dgClient.Rows.Add()
dgClient.Rows(i).Cells("client").Value = dsClient.Tables("TableClient").Rows(i).Item("Client")
dgClient.Rows(i).Cells("comments").Value = dsClient.Tables("TableClient").Rows(i).Item("Comments")
Next
How I can do above using C#
Thanks in advance
How to add rows from dataset to datagridview
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Manoj Bist15 pointsPosted Aug 29, 2006, 6:15 PM EDT
Here is your C# code
dgClient.Columns.Add ("client", "Client");
dgClient.Columns["client"].Width = 150;
dgClient.Columns.Add("comments", "Comments");
dgClient.Columns["comments"].Width = 250;
for(int i= 0; i<= dsClient.Tables["TableClient"].Rows.Count - 1; i++)
{
dataGridView1.Rows.Add();
dgClient.Rows[i].Cells["client"].Value = dsClient.Tables["TableClient"].Rows[i]["Client"];
dgClient.Rows[i].Cells["comments"].Value = dsClient.Tables["TableClient"].Rows[i]["Comments"];
}