CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    123

    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

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: GUI Refresh issue

    Are you assigning a delegate to the PropertyChangeEventHandler in your GUI class? I don't see it there.

  3. #3
    Join Date
    Apr 2004
    Posts
    123

    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.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    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
  •  





Click Here to Expand Forum to Full Width

Featured