Hi,
My Winform application has a datagridview dgvTag and a button btnGen in a User Control. Clicking the button will generate the data in a datatable dtTag which is set as the data source of the datagridview. The code is like this:
private void btnGen_Click(object sender, EventArgs e)
{
dtTag.Reset();
dtTag.Columns.Add("A", typeof(string));
dtTag.Columns.Add("B", typeof(string));
dtTag.Columns.Add("C", typeof(string));
dtTag.Columns.Add("D", typeof(string));
dtTag.Columns.Add("E", typeof(string));
dtTag.Columns.Add("F", typeof(string));
dtTag.Columns.Add("G", typeof(string));
//put the code here to generate the tags
dgvTag.DataSource = dtTag;
MessageBox.Show("Database generated.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Somehow, this code only works for the first time. If the button was clicked for the 2nd time, the datagridview becomes empty while only column headers are still there. I am sure the datatable dtTag is not not empty. Could you please help on this? Thanks.