How to bind data displayed in a DataGrid(wpf) to database?

Good time of day. I can't find the solution to this problem. We need to implement the program RealTime, that is, there was a change in the DB, the DataGrid is updated, or simply display relevant data. As database I use MySQL. Thank you in advance for your help)
July 8th 19 at 16:32
3 answers
July 8th 19 at 16:34
Solution
The timer, or the file system watch.
I tried the timer, but the update is happening, apparently, and scan the difference between the data in the grid database and correcting of the cell, a very dreary affair. Given that the BD remote - the file system monitor is not an option. There must be some sort of loyal solution) - sister commented on July 8th 19 at 16:37
July 8th 19 at 16:36
Solution
dataGrid.ItemsSource = dataFromMySql;

var timer = new System.Windows.Threading.A DispatcherTimer();
timer.Tick += (oe,e)=> dataGrid.Items.Refresh(); 
/* or */
/* timer.Tick += (oe,e)=> { dataGrid.ItemsSource = null; dataGrid.ItemsSource = dataFromMySql; } */
timer.Interval = new TimeSpan(0,0,10);
timer.Start();
July 8th 19 at 16:38
Solution
The decision was such.
private void initializeTimer()
{
 var a DispatcherTimer = new System.Windows.Threading.A DispatcherTimer();
 a DispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
 a DispatcherTimer.Interval = new TimeSpan(0, 0, 5);
a DispatcherTimer.Start();
}

 private void dispatcherTimer_Tick(object sender, EventArgs e)
{
Companies.companies.Clear();
Companies.Get();
grid.Items.Refresh();
 }

static class Companies
{
 public static System.Data.DataSet companies = new System.Data.DataSet();

 public static System.Data.DataView Get()
{
User.connect.Open();
 MySqlCommand cmd = new MySqlCommand("SELECT * FROM data" User.connect);
 MySqlDataAdapter adapter = new MySqlDataAdapter();
 adapter.SelectCommand = cmd;
adapter.Fill(companies);
User.connect.Close();
 return new System.Data.DataView(companies.Tables[0]);
}
 }
for example, the user or the code changes the data, and you are on a timer they are cleaned completely, and then fill again and the user will lose entered data. - sister commented on July 8th 19 at 16:41
in the event of a start input to stop it
at the end - restart - Josef commented on July 8th 19 at 16:44
and, accordingly, before starting the timers and they are added to the database - sister commented on July 8th 19 at 16:47

Find more questions by tags WPFC#