- DataSet ds = new DataSet();
- //Assuming that ds already contains record populated from database
- DataRow rs1 = ds.Tables[0].NewRow();
- DataRow rs2 = ds.Tables[0].NewRow();
- rs1["COL1"] = "Testing row1col1"; rs1["COL2"] = "Testing row1col2";
- rs2["COL1"] = "Testing row2col1"; rs2["COL2"] = "Testing row2col2";
- ds.Tables[0].Rows.Add(r1);
- ds.Tables[0].Rows.Add(r2);
- DataView dv = ds.Tables[0].DefaultView;
- DataGrid dg = new DataGrid();
- dg.DataSource = dv;
Wednesday, July 30, 2008
Adding Rows to DataGrid
One day my colleague want me to add some rows to existing DataGrid, the rest of the record is populate with query from the database meanwhile the records that will be add should be filled manually and not from database, for few minutes I feel foolish enough to find out that we can't add rows using the DataGrid object directly like we add rows in DataTable (Creating DataTable Manually), but we should manipulate the DataGrid.DataSource that I fill in with DataView object. So we should manipulate the DataTable and not the DataGrid, the code is quite same like my previous post (Creating DataTable Manually) with some lines added.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment