hi,
I am having the following problem. I have created an object and I populate the object with values from my MySql database. Each object in added to a list(collection). I then databind this list of objects to the itemsource of a datagrid. I make use of an objectdataprovider. My problem is that if changes are made in my database, my collection is not updated and therefore my UI isn't updated. Any suggestions on what can be done. I new to programming and WPF and I havent got a clue.
Please help.
Following is the code:
public class CompressorEngine : ObservableCollection <power>
{
public static ArrayList GetCompressor()
{
MySqlConnection conn = new MySqlConnection(" ");
conn.Open();
MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "SELECT ABIUnits.UnitSerialNumber, Region, AssetDescription, Location_Latitude, Location_Longitude, Street, City, ABIUnits_Alerts.Time, ABIUnits_Alerts.Comment, Alert_Type, Alert_ID FROM ABIUnits JOIN ABIUnits_Alerts ON ABIUnits.UnitSerialNumber = ABIUnits_Alerts.UnitSerialNumber WHERE ABIUnits_Alerts.Checked = '" + 0 + "' AND ABIUnits_Alerts.AlertGroup = '" + 3 + "' ORDER BY ABIUnits_Alerts.Time Desc";
MySqlDataReader reader = comm.ExecuteReader();
string alert_id;
string unitserialnumber;
string alerttype;
string time1;
string assetdescription;
string region;
string location_latitude;
string location_longitude;
string street;
string city;
ArrayList plist = new ArrayList();
Compressor titlepower = new Compressor("Alert ID", "Unit Serial Number", "Alert", "Time", "Description", "Latitude", "Longitude", "Region", "Street", "City");
plist.Add(titlepower);
while (reader.Read())
{
alert_id = reader["ALert_ID"].ToString();
unitserialnumber = reader["UnitSerialNumber"].ToString();
alerttype = reader["ALert_Type"].ToString();
time1 = reader["Time"].ToString();
assetdescription = reader["AssetDescription"].ToString();
region = reader["Region"].ToString();
location_latitude = reader["Location_Latitude"].ToString();
location_longitude = reader["Location_Longitude"].ToString();
street = reader["Street"].ToString();
city = reader["City"].ToString();
Compressor compressor = new Compressor(alert_id, unitserialnumber, alerttype, time1, assetdescription, location_latitude, location_longitude, region, street, city);
plist.Add(compressor);
}
conn.Close();
return plist;
}
}
public class Compressor : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string info)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(info));
}
}
private string _p_id;
private string _units;
private string _alert;
private string _time;
private string _assetdescription1;
private string _location_latitude1;
private string _location_longitude1;
private string _region1;
private string _street1;
private string _city1;
public Compressor(string p_id, string units, string alert, string time, string assetdescription1, string location_latitude1, string location_longitude1, string region1, string street1, string city1)
{
_p_id = p_id;
_units = units;
_alert = alert;
_time = time;
_assetdescription1 = assetdescription1;
_location_latitude1 = location_latitude1;
_location_longitude1 = location_longitude1;
_region1 = region1;
_city1 = city1;
_street1 = street1;
}
public string P_id
{
get { return _p_id; }
set { _p_id = value; OnPropertyChanged("P_id"); }
}
public string Units
{
get { return _units; }
set { _units = value; OnPropertyChanged("Units"); }
}
public string Alert
{
get { return _alert; }
set { _alert = value; OnPropertyChanged("Alert"); }
}
public string Time
{
get { return _time; }
set { _time = value; OnPropertyChanged("Time"); }
}
public string AssetDescription1
{
get { return _assetdescription1; }
set { _assetdescription1 = value; OnPropertyChanged("AssetDescription1"); }
}
public string Location_Latitude1
{
get { return _location_latitude1; }
set { _location_latitude1 = value; OnPropertyChanged("Location_Latitude1"); }
}
public string Location_Longitude1
{
get { return _location_longitude1; }
set { _location_longitude1 = value; OnPropertyChanged("Location_Longitude1"); }
}
public string Region1
{
get { return _region1; }
set { _region1 = value; OnPropertyChanged("Region1"); }
}
public string Street1
{
get { return _street1; }
set { _street1 = value; OnPropertyChanged("Street1"); }
}
public string City1
{
get { return _city1; }
set { _city1 = value; OnPropertyChanged("City1"); }
}
}
</power>