After entering data into all the textbox, and after clicking the submit button, it won\'t immediately show in the datagridview, I need to reopen the form in order to see the
Use LoadPatientRecords()
after a successful insertion.
Try the below code
private void btnSubmit_Click(object sender, EventArgs e)
{
if (btnSubmit.Text == "Clear")
{
btnSubmit.Text = "Submit";
txtpFirstName.Focus();
}
else
{
btnSubmit.Text = "Clear";
int result = AddPatientRecord();
if (result > 0)
{
MessageBox.Show("Insert Successful");
LoadPatientRecords();
}
else
MessageBox.Show("Insert Fail");
}
}
Try refreshing the datagrid after each insert
datagridview1.update();
datagridview1.refresh();
Hope this helps you!
You can set the datagridview
DataSource
to null
and rebind it again.
private void button1_Click(object sender, EventArgs e)
{
myAccesscon.ConnectionString = connectionString;
dataGridView.DataSource = null;
dataGridView.Update();
dataGridView.Refresh();
OleDbCommand cmd = new OleDbCommand(sql, myAccesscon);
myAccesscon.Open();
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable bookings = new DataTable();
da.Fill(bookings);
dataGridView.DataSource = bookings;
myAccesscon.Close();
}
Only need to fill datagrid again like this:
this.XXXTableAdapter.Fill(this.DataSet.XXX);
If you use automaticlly connect from dataGridView this code create automaticlly in Form_Load()
In the form designer add a new timer using the toolbox. In properties set "Enabled" equal to "True".
The set the DataGridView
to equal your new data in the timer
I don't know if you resolved your problem, but a simple way to resolve this is rebuilding the DataSource (it is a property) of your datagridview. For example:
grdPatient.DataSource = MethodThatReturnList();
So, in that MethodThatReturnList() you can build a List (List is a class) with all the items you need. In my case, I have a method that return the values for two columns that I have on my datagridview.
Pasch.