This is a migrated thread and some comments may be shown as answers.

Refresh btn

3 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hamid va
Top achievements
Rank 1
Hamid va asked on 26 Dec 2010, 10:42 AM
Hi , sorry for my bad english.

I have use multiple gird in my main form (Entity framework , databindingsource) .
i have refresh button on main form and i want refresh all grid data .(data changed on other form)


what is a best solution ?


 

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 26 Dec 2010, 11:32 AM
Hello,

The easiest and cleanest way to do this is to create an event on the main form and register all other forms to that event, and just connect that event to the refresh button.

Or an even easier solution (but not that clean) create a static event on the main form and register to that from all other forms, that way you won't need an instance of the main form.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Hamid va
Top achievements
Rank 1
answered on 26 Dec 2010, 12:04 PM
thanks for your reply . 
can you show me with some couple of code .

 
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 26 Dec 2010, 12:17 PM
Hello again,

The easiest way i could think of is this, creating a static class, with an event and a call refresh or perform refresh method.

Please take a look at the following example:
public static class GridRefresher
{
    public static event EventHandler RefreshGridsCalled;
 
    public static void PerformGridRefresh()
    {
        if (RefreshGridsCalled != null)
        {
            RefreshGridsCalled(null, EventArgs.Empty);
        }
    }
 
}
 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        GridRefresher.RefreshGridsCalled += new EventHandler(GridRefresher_RefreshGridsCalled);
    }
 
    void button_Click(object sender, EventArgs e)
    {
        GridRefresher.PerformGridRefresh();
    }
 
    void GridRefresher_RefreshGridsCalled(object sender, EventArgs e)
    {
            // get data from db and refresh Grid
    }
}
Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP

Tags
GridView
Asked by
Hamid va
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Hamid va
Top achievements
Rank 1
Share this question
or