C# grid binding not update

前端 未结 3 804
醉话见心
醉话见心 2021-01-22 09:37

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 cli

相关标签:
3条回答
  • 2021-01-22 10:12

    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.

    0 讨论(0)
  • 2021-01-22 10:18

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

    0 讨论(0)
  • 2021-01-22 10:18

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

    0 讨论(0)
提交回复
热议问题