I have followed the tutorial to the letter and the error associated with 'ltvTreatments' when it executes the code below is "AccessibilityObject = 'ltvTreatments.AccessibilityObject' threw an exception of type 'System.InvalidOperationException'".
Code: Select all
private void dependency_OnChange(object sender, MySqlTableChangeEventArgs e)
{
ltvTreatments.Invoke(new NotifyDelegate(AddChangedList), new object[] { e.TableName });
}
Full Code list below, as descriptive as possible. I am desperate to understand my error so would be extremely grateful for anyone to assist.
Code: Select all
public void CaseDataChangeEventStart()
{
string connectionString = "User Id=xxxxx;Password=xxxxx;Host=localhost;Database=avcasesdb;";
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
MySqlCommand mySqlCommand = new MySqlCommand("select * from casetable", connection);
MySqlDependency dependency = new MySqlDependency(mySqlCommand, 100);
dependency.OnChange += new Devart.Data.MySql.OnChangeEventHandler(dependency_OnChange);
MySqlDependency.Start(connectionString);
}
private void dependency_OnChange(object sender, MySqlTableChangeEventArgs e)
{
ltvTreatments.Invoke(new NotifyDelegate(AddChangedList), new object[] { e.TableName });
}
private void AddChangedList(string tablename)
{
CasesRepo casesRepo = new CasesRepo();
currentCase = casesRepo.GetLastTreatment();
ListViewItem item1 = new ListViewItem(currentCase[0].CaseNumber.ToString());
ListViewItem item2 = new ListViewItem(currentCase[0].CaseTime);
ListViewItem item3 = new ListViewItem(currentCase[0].CaseTreatment);
try
{
ltvTreatments.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
}
catch (Exception ex)
{
}
}