views:

910

answers:

3

I have a grid that is binded to a collection. For some reason that I do not know, now when I do some action in the grid, the grid doesn't update.

Situation : When I click a button in the grid, it increase a value that is in the same line. When I click, I can debug and see the value increment but the value doesn't change in the grid. BUT when I click the button, minimize and restore the windows, the value are updated... what do I have to do to have the value updated like it was before?

UPDATE This is NOT SOLVED but I accepted the best answer around here.

It's not solved because it works as usuall when the data is from the database but not from the cache. Objects are serialized and threw the process the event are lost. This is why I build them back and it works for what I know because I can interact with them BUT it seem that it doesn't work for the update of the grid for an unkown reason.

A: 

It sounds like you need to call DataBind in your update code.

BioBuckyBall
A: 

I am using the BindingSource object between my Collection and my Grid. Usually I do not have to call anything.

Daok
+2  A: 

In order for the binding to be bidirectional, from control to datasource and from datasource to control the datasource must implement property changing notification events, in one of the 2 possible ways:

  • Implement the INotifyPropertyChanged interface, and raise the event when the properties change :

    public string Name 
    {
      get
      {
        return this._Name;
      }
      set
      {
        if (value != this._Name)
        {
            this._Name= value;
            NotifyPropertyChanged("Name");
        }
      }
    }
    
  • Inplement a changed event for every property that must notify the controls when it changes. The event name must be in the form PropertyNameChanged :

    public event EventHandler NameChanged;
    
    
    public string Name 
    {
      get
      {
        return this._Name;
      }
      set
      {
        if (value != this._Name)
        {
            this._Name= value;
            if (NameChanged != null) NameChanged(this, EventArgs.Empty);
        }
      }
    }
    

    *as a note your property values are the correct ones after window maximize, because the control rereads the values from the datasource.

Pop Catalin
Pop Catalin you have a point, and this is already done. I have 2 grids in the project with the SAME object and 1 grid work and the other not :(
Daok
You mean, you have an object (1 instance) that is bound in 2 grids at the same time? And the button is in one of the grids? If that's the case, you need to call EndEdit() on your binding source so edits are propagatet to the datasource, and then are visible in second grid.
Pop Catalin
I just realise that all is fine but not when the grid is loading from our Cache System. It might be the serialization that cut something. I'll check
Daok