• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

refresh form with datagridview

I have a windform with DataGridView display a list of data with a DataGridViewButtonColumn. When I clicked the button, a popup window will display some info and I could make changes. And after I clicked a button in popup. Some data updated in DB. And popup closed. But the content of my DataGridView in first firm should have changed. But not updated I could not see the changes I made. I know I should update the form or the datasource of DataGridView so that I could see the changes after the popup closed. I tried this.update(); this.refresh(); invalidate.....Just not working correctly.
But It worked if I reload the form. The problem is I don't want to reload the whole form?

How to handle it? Appreciated!!
0
jssong2000
Asked:
jssong2000
1 Solution
 
Rose BabuSenior Team ManagerCommented:
Hi,

Try this simple way.

in Form1, Write the data binding code in a subroutine

and at the end of the button click which is used to open popup form, call the binding subroutine process.

This will refresh the datagridview.

Try like this.

namespace WinAppCSHARP
{
    public partial class Form1 : Form
    {                
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            BindGrid();
        }

        public void BindGrid()
        {
            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();
            
            dataGridView1.DataSource = YourDataSource;            
        }        

        private void btnOpenPopup_Click(object sender, EventArgs e)
        {
		
	    // Opens Popup window
            frmPopup frm = new frmPopup();
            frm.ShowDialog();

	    // Load DataGridView again
            BindGrid();
        }
    }
}

Open in new window

0
 
jssong2000Author Commented:
It worked. Thank You!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now