I have DataGridView and DataTable, DataTable is assigned as a datasource in DataGridView.
When I change some value in DataTable it is not update on the view.
So How can i achive this
I have tried following things
Demo Code
DataGridView datagrid = new DataGridView();
DataTable dt = new DataTable();
dt.Columns.Add("No");
dt.Columns.Add("Name");
for (int i = 1; i <= 10; i++)
{
DataRow row = dt.NewRow();
row[0] = i;
row[1] = "ABC";
dt.Rows.Add(row);
}
datagrid.DataSource = dt;
Here my above code
When i change some value in DataTable it is not reflect in DataGridView
dt.Rows[0][1] = "XYZ";
So Please help me....
I am able to do this, which works:
private DataTable _dt = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
_dt.Columns.Add("LongText");
DataRow dr = _dt.NewRow();
dr[0] = "One";
_dt.Rows.Add(dr);
dr = _dt.NewRow();
dr[0] = "Two";
_dt.Rows.Add(dr);
dr = _dt.NewRow();
dr[0] = "Three";
_dt.Rows.Add(dr);
dataGridView1.DataSource = _dt;
}
private void button1_Click(object sender, EventArgs e)
{
_dt.Rows[0][0] = "daddy";
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments