-
November 20th, 2008, 06:26 PM
#1
GUI Refresh issue
Hi,
I have a bindinglist(source) of objects(Record) and the list is bound to a grid.Now,inside the object I have a callback method which gets invoked by a different thread to inform about a particular status to the user.The object has a field called status which gets updated inside the callback method.Now,since this change should be reflected in the GUI I have implemented INotifyPropertyChanged.But still it does’t get reflected.What ‘am I doing wrong?Is this the correct way to do it?
Code:
//GUI Thread
BindlingList<Record> source = new BindlingList<Records>();
myGrid.DataSource = source
//GUI Thread
public class Record: INotifyPropertyChanged
{
private string _status;
public string Status
{
get{ return _status;}
set
{
if (_status != value)
{
_status = value;
NotifyPropertyChanged("Status");
}
}
}
//BACKGROUND THREAD
Public void Callback(CustomStatus statusObj)
{
_status = statusObj.Status;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
Thanks in advance for your help.
Mmx
-
November 20th, 2008, 06:30 PM
#2
Re: GUI Refresh issue
Are you assigning a delegate to the PropertyChangeEventHandler in your GUI class? I don't see it there.
-
November 20th, 2008, 06:47 PM
#3
Re: GUI Refresh issue
I did't quite understand "assigning a delegate in GUI class".Can you explain a little bit more??
Please note that the object creation,adding to binding list etc all happends in GUI thread.Inside the object there is a callback method,which is called periodically by a service.
-
November 20th, 2008, 07:28 PM
#4
Re: GUI Refresh issue
Code:
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
Set a break point inside of that if statement. I bet it never gets hit. You need to handle the event from you GIU thread.
Code:
mygrid.PropertyChanged += new PropertyChangedEventHandler(mygrid_PropertyChanged);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|