I've created an application that will display the data of a given view in a datagridview
control.
The whole application is ready: loading the data, the button to update and also the events load
and activated
.
Technologies used:
- ADO.NET Entity Data Model
- EF 6.x EntityObject Generator
- SQL Server 2012
Note: I am using the BindingSource in the DataSource property of the datagridview to load the information.
Here is the code for my application:
private void frmDados_Load(object sender, EventArgs e)
{
CarregaDados();
}
private void CarregaDados()
{
using (var context = new DadosEntities())
{
vGRUPOSBindingSource.DataSource = context.VGRUPOS.ToList();
}
}
private void btnAtualizar_Click(object sender, EventArgs e)
{
CarregaDados();
}
/// <summary>
/// Evento acionado quando o foco retornar ao formulário
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmDados_Activated(object sender, EventArgs e)
{
CarregaDados();
}
My question
How do I update the datagridview
control automatically after any changes to the table data?
Be directed by the database or by another open application being fed by other users.
The control needs to be updated without any influence of the user - activating the focus on the application or clicking the Refresh button.
Sample scenario
With my open application, defined as an dashboard , the product stock information is displayed. As another application a stock control (in WinForm, Mobile or WEB) gives inputs or outputs, my dashboard app needs to show the new information.
It can also happen from a batch operation, updating the stock of many products via the database, that is, a update
directly by SQL
, so my dashboard needs to update the information in real time no datagridview
.