Answers
Mar 08, 2009 - 01:40 AM
What you can do is create a new datarow and add that to a datatable. That then goes to a dataview which you associate to the datagrid. This example is in vb.net but it should be easy enough to translate to c#
Ive added comments in to help you out
'Define a datatable, datarow and dataview
Dim dt As DataTable
Dim dr As DataRow
Dim dw As DataView
'Associate the currnt datasource to the data table
dt = DataGrid1.DataSource
'Create a new row
dr = dt.NewRow()
'Populate the fields in that datatable
dr("ID") = "100"
dr("MyValue") = "Quomon"
'Add this new DataRow to the DataTable
dt.Rows.Add(dr)
'Now add that DataTable to a new instance of a DataView
dw = New DataView(dt)
'And finally add that dataview to the DataGrid datasource
DataGrid1.DataSource = dw
Ive added comments in to help you out
'Define a datatable, datarow and dataview
Dim dt As DataTable
Dim dr As DataRow
Dim dw As DataView
'Associate the currnt datasource to the data table
dt = DataGrid1.DataSource
'Create a new row
dr = dt.NewRow()
'Populate the fields in that datatable
dr("ID") = "100"
dr("MyValue") = "Quomon"
'Add this new DataRow to the DataTable
dt.Rows.Add(dr)
'Now add that DataTable to a new instance of a DataView
dw = New DataView(dt)
'And finally add that dataview to the DataGrid datasource
DataGrid1.DataSource = dw
Mar 08, 2009 - 01:42 AM
I think this is the c# equivalent
It assumes u have a datagrid control called dataGrid1
and datasource has 2 columns ID and MyValue
DataTable dt;
DataRow dr;
dt = DataGrid1.DataSource;
dr = dt.NewRow();
dr("ID") = "100"
dr("MyValue") = "Quomon"
dt.Rows.Add(dr)
DataView dw = new DataView(dt);
dataGrid1.DataSource = dw;
It assumes u have a datagrid control called dataGrid1
and datasource has 2 columns ID and MyValue
DataTable dt;
DataRow dr;
dt = DataGrid1.DataSource;
dr = dt.NewRow();
dr("ID") = "100"
dr("MyValue") = "Quomon"
dt.Rows.Add(dr)
DataView dw = new DataView(dt);
dataGrid1.DataSource = dw;
Apr 06, 2009 - 03:01 AM
The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.
The Quomon Team
The Quomon Team
Add New Comment