Click here to Skip to main content
16,012,843 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to add rows from a dataset to datagridview with out using databinding
Please help...............



If there are few columns then The below code is Helping me . but in case of more columns this is not a goodway
VB
dgClient.Columns.Add("client", "Client")
dgClient.Columns("client").Width = 150
dgClient.Columns.Add("comments","Comments")
dgClient.Columns("comments").Width = 250 
Dim i As IntegerFor 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
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
Posted
Updated 12-Dec-11 20:55pm
v2
Comments
[no name] 13-Dec-11 2:36am    
is this static data or you will also save in database?

VB
For i = 0 To frm.dgvDetail.Rows.Count - 1                   For j = 0 To frm.dgvDetail.Columns.Count - 1
                       frm.dgvDetail.Item(frm.dgvDetail.Columns(j).Name, i).Value = dsCOA.Tables("tblFind").Rows(i)(frm.dgvDetail.Columns(j).Name)
                   Next
               Next
 
Share this answer
 
At click event of add new button do following sequence:
1. using foreach loop, put all the records of grid in a dataset
2. add one blank row to dataset.
3. bind dataset again to grid.
this will show a new row in grid without impacting grid data.
 
Share this answer
 
 
Share this answer
 
Just create a temp Table with dataset and give this as datasource of a datagridview.

In datatable you can add row one by one and can do modification which you want while adding values. And then after creating you just have to give as datasource.


OR clear your requirement why you want like this.
 
Share this answer
 
Comments
Member 8390746 13-Dec-11 3:02am    
I also want to add new rows to the datagrid and edit the existing rows and then save back to the database.If i am using the datasource property ,it is possible to add new row delete rows etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900