2011-07-03 4 views
0

저는 vs2010에서 일하고 있습니다. ObservableCollection List에 바인드 된 DataGrid를 만들었습니다. 나는 다른 창에 전달 사 개 대표가WPF DataGrid-DataGridCheckBoxColumn vs2010 C# .net

public class Class_RetrieveCommand 
{ 
    public string CMD { get; set; } 
    public bool C_R_CMD { get; set; } 
    public bool S_CMD { get; set; } 
    public bool C_S_CMD { get; set; } 
} 

,이 창은 런타임시 목록을 업데이트 할 필요가 :

는 Class_CMD은 다음과 같습니다. 런타임 동안 나는 항상 업데이트 된 그리드의 문자열 열을 볼 수 있지만 DataGridCheckBoxColumns는 결코 업데이트되지 않습니다.

DataGrid에 - 부울을 업데이트 대의원의

<DataGrid Background="Transparent" x:Name="DataGrid_CMD" Width="450" MaxHeight="450" Height="Auto" ItemsSource="{Binding}" AutoGenerateColumns="True"> 

하나입니다 -

public void UpdateC_S_CMD(string Msg) 
    { 
     foreach (Class_CMD c in List.ToArray()) 
     { 
      if (c.CMD.Equals(Msg)) 
       c.C_S_CMD = true; 
     } 
    } 

이 이해하지 않는 부울 열이 업데이트되지 않는 이유는 .... 사람이 할 수있는 도와주세요? 덕분에 .

답변

2

클래스 Class_RetrieveCommand는 INotifyPropertyChanged 인터페이스를 구현해야합니다. 그렇지 않으면 클래스의 인스턴스에 바인드 된 개별 행 데이터는 기본 속성이 변경되었음을 알지 못합니다.

public class Class_RetrieveCommand : INotifyPropertyChanged 
{ 
    private string _CMD; 
    public string CMD 
    { 
     get { return _CMD; } 
     set { _CMD = value; OnPropertyChanged("CMD"); } 
    } 

    ... similar for the other properties 

    public event PropertyChangedEventHandler PropertyChanged; 
    private void OnPropertyChanged(string propertyName) 
    { 
     var handler = PropertyChanged; 
     if (handler != null) 
     { 
      handler(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

것은 불행하게도 당신이 자동차를 사용할 수 없습니다

public class Class_RetrieveCommand : INotifyPropertyChanged 
{ 
    private bool _cRCmd; 
    private bool _cSCmd; 
    private string _cmd; 
    private bool _sCmd; 

    public string CMD 
    { 
     get { return _cmd; } 
     set 
     { 
      _cmd = value; 
      InvokePropertyChanged(new PropertyChangedEventArgs("CMD")); 
     } 
    } 

    public bool C_R_CMD 
    { 
     get { return _cRCmd; } 
     set 
     { 
      _cRCmd = value; 
      InvokePropertyChanged(new PropertyChangedEventArgs("C_R_CMD")); 
     } 
    } 

    public bool S_CMD 
    { 
     get { return _sCmd; } 
     set 
     { 
      _sCmd = value; 
      InvokePropertyChanged(new PropertyChangedEventArgs("S_CMD")); 
     } 
    } 

    public bool C_S_CMD 
    { 
     get { return _cSCmd; } 
     set 
     { 
      _cSCmd = value; 
      InvokePropertyChanged(new PropertyChangedEventArgs("C_S_CMD")); 
     } 
    } 

    #region INotifyPropertyChanged Members 

    public event PropertyChangedEventHandler PropertyChanged; 

    #endregion 

    public void InvokePropertyChanged(PropertyChangedEventArgs e) 
    { 
     PropertyChangedEventHandler handler = PropertyChanged; 
     if (handler != null) 
     { 
      handler(this, e); 
     } 
    } 
} 
+0

대단히 감사합니다. 지금 사용해 보겠습니다. –

+0

작품, 고마워요 !!!!!!! –

1

당신은이 같은 Class_RetrieveCommandINotifyPropertyChanged를 구현해야합니다 :이 같은 뭔가를 변경하는 경우, 당신은 당신의 그리드에 반영 변경 사항을 볼 수 이제는 속성을 더 이상 사용하지 않습니다 (프록시 생성자를 사용하는 경우 제외).

+0

대단히 감사합니다 !!! –