Some time DataGrid Can't synchronous display after Edit

Aug 22, 2010 at 6:19 AM
Edited Aug 22, 2010 at 6:22 AM

I have some DataGrid like this:

        <DataGrid Name="dgList" AutoGenerateColumns="False" IsReadOnly="True" CanUserAddRows="True" ItemsSource="{Binding}">
          <DataGrid.Columns>
            <DataGridTextColumn Header="NO." Binding="{Binding Path=NO}"/>
            <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>
            <DataGridTextColumn Header="Description" Binding="{Binding Path=Description}"/>
            <DataGridCheckBoxColumn Header="Enable" Binding="{Binding Path=En}"/>
          </DataGrid.Columns>
        </DataGrid>

And I have a Class as follows:

  public class Level : INotifyPropertyChanged
  {

    private string _Name;
    public virtual string Name
    {
      get
      {
        return _Name;
      }
      set
      {
        if (value != _Name)
        {
          _Name = value;
          PropChanged();
        }
      }
    }

    private int _id;
    public virtual int ID 
    {
      get
      {
        return _id;
      }
      set
      {
        if (value != _id)
        {
          _id = value;
          PropChanged();
        }
      }
    }

    private string _no;
    public virtual string NO 
    {
      get
      {
        return _no;
      }
      set
      {
        if (value != _no)
        {
          _no = value;
          PropChanged();
        }
      }
    }

    private string _desc;
    public virtual string Description 
    {
      get
      {
        return _desc;
      }
      set
      {
        if (value != _desc)
        {
          _desc = value;
          PropChanged();
        }
      }
    }

    private bool _en;
    public virtual bool En 
    {
      get
      {
        return _en;
      }
      set
      {
        if (value != _en)
        {
          _en = value;
          PropChanged();
        }
      }
    }

    public virtual event PropertyChangedEventHandler PropertyChanged;
    protected void PropChanged()
    {
      PropertyChangedEventHandler handler = PropertyChanged;
      if (handler != null)
      {
        _isChanged = true;
        string name = new StackTrace().GetFrame(1).GetMethod().Name.Substring(4);
        handler(this, new PropertyChangedEventArgs(name));
      }
    }
  }

Then, i Get a Level Collection and Binding to dgList

List<Level> ldl;
ldl = GetList();

Binding bind = new Binding();
bind.Source = ldl;
bind.Path = new PropertyPath(".");
bind.Mode = BindingMode.OneWay;

dgList.SetBinding(DataGrid.ItemsSourceProperty, bind);


When i edit the Level instance as follows

EditPage ep  = new EditPage(dgList.SelectedItem as Level);
ep.Show();

it's has problems

1)in some dgList, all row can synchronous display after edit in ed;

2)in some dgList, the first row can synchronous display after edit in ep;
other row can't synchronous display after edit in ep, but in this time, the Level instance in dgList ItemsSource is new value;

3)in some dgList, all row can't synchronous dispplay after edit in ep;
but in this time, the Level instance in dgList ItemsSource is new value
Example: the Name of first row in dgList is "MyName", then i edit Name to "MyName is Test" in ep, it's display "MyName" yet in first row in dgList, but the Name of dgList[0] is "MyName is Test" already.

Who can help me?