I have two datagridview inside a winform. I need to reload with a button the second datagridview 2 when I change the data inside the datagridview1.
datagriview1 modified —> click button update —> reload datagridview 2.
it’s not working I don’t know why.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
DataSet ds = new DataSet();
DataSet dv = new DataSet();
public Form1()
{
InitializeComponent();
FileStream stream = new FileStream("file.xml",FileMode.Open);
ds.ReadXml(stream);
stream.Close();
dataGridView1.DataSource = ds.Tables[0];
FileStream stream1 = new FileStream("file.xml", FileMode.Open);
dv.ReadXml(stream1);
stream1.Close();
dataGridView2.DataSource = dv.Tables[0];
//DateTime Today = DateTime.Now;
}
private void updateData_Click(object sender, EventArgs e)
{
ds.WriteXml("file.xml");
//reload the datagridview 2 after modification intot the datagridview1
dv.reset();
FileStream stream1 = new FileStream("file.xml", FileMode.Open);
dv.ReadXml(stream1);
stream1.Close();
dataGridView2.DataSource = dv.Tables[0];
dataGridView2.ResetBindings();
}
}
}
There’s a
ResetBindingsfunction onDataGridthat should do what you want.dataGridView2.ResetBindings();