2011-03-08 7 views
0

안녕하세요 저는 데이터 박스를 체크 박스로 만들었지 만 체크 박스의 상태를 가져 오는 방법을 모르거나 체크하지 않았습니다. INotifyPropertyChanged를 사용하는 것이 좋습니다. CellEditEnding 이벤트 처리기의 입니다. 제발 내가 donot 알고 어떻게 내가 이들 중 하나를 구현할 수 있습니다.다른 셀의 값 가져 오기 DataGrid WPF

내가 원하는 것은 사용자가 클릭하여 체크/체크하지 않은 체크 박스의 값을 확인하는 것입니다. 해당 행의 첫 번째 셀에서 행 인덱스와 값을 가져올 수 있습니다.

내 코드는 지금까지

namespace embeddatagridcheckbox 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     List<checkedBoxIte> item = new List<checkedBoxIte>(); 
     public MainWindow() 
     { 
      InitializeComponent(); 
      for (int i = 0; i < 5; i++) 
      { 
       checkedBoxIte ite = new checkedBoxIte(); 
       ite.MyString = i.ToString(); 
       ite.MyBool = false; 
       item.Add(ite); 
      } 
      dataGrid1.ItemsSource = item; 
     } 
    } 

    public class checkedBoxIte 
    { 
     public string MyString { get; set; } 
     public bool MyBool { get; set; } 
    } 
} 

XML 당신이에서 CheckBox의 값을 참조 할 않는

<DataGrid AutoGenerateColumns="False" Height="323" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="503" BeginningEdit="dataGrid1_BeginningEdit"> 
      <DataGrid.Columns> 
       <DataGridTextColumn Header="MyString" Binding="{Binding MyString}" /> 
       <DataGridCheckBoxColumn Header="MyBool" Binding="{Binding MyBool}" /> 
      </DataGrid.Columns> 
     </DataGrid> 
+0

에서 INotifyPropertyChanged의 체크 박스 값이 사용됩니다. UI에서 코드의 개체로의 반대 변경은 기본적으로 작동합니다. – vorrtex

답변

2

이다? 일반적으로 DataGrid의 ItemSource 객체를 사용하여 행/열을 계산하는 대신 직접 작업 할 것이지만 그 작업은 수행하려는 작업에 따라 다릅니다.

예를 들어, 코드 숨김에서 list이라는 목록에있는 체크 상자의 상태가 사용자의 DataGrid에 바인딩 된 것이므로 찾을 수 있습니다. 당신은 C# 코드에서 객체를 변경하고 인터페이스를 업데이트 할 때

list[0] = 첫 번째 행의 데이터

list[0].MyBool = 첫 번째 행

관련 문제