0

これが私の問題です。学生が入力されたチェックリスト ボックスがあります。チェックボックスをオンにして学生を選択すると、データグリッドに表示されます。また、学生がチェックされていない場合は、データ グリッドから削除する必要があります。

コレクションをチェックリスト ボックスにバインドすることはできますが、学生がチェックされている場合、変更されたプロパティがバインドされているコレクションの子であるため、プロパティ変更イベントが発生しません。そのため、変更されたプロパティもコレクションに追加しました。

以下は、私が遊んでいるコードの一部です。

バインドされている場所:

public IEnumerable<SelectedStudent> ActiveStudents
{
    get { return _activeStudents; }
    set
    {
        _activeStudents = value;
        RaisePropertyChanged("ActiveStudents");
        RaisePropertyChanged("GridDisplay");
    }
}

public IEnumerable<SelectedStudent> GridDisplay
{
    get
    {
        var aa = _activeStudents.Where(a => a.Select == true);
        return aa;
    }
    set
    {
        _activeStudents = value;
        RaisePropertyChanged("GridDisplay");
    }
}

選択された学生クラス:

#region Fields

        private int _studentId;
        private string _firstName;
        private string _lastName;
        private bool _printCertificate;
        private bool _select;
        private int _testDateId;
        private string _rank;

        #endregion

public int StudentId
{
    get { return _studentId; }
    set
    {
        _studentId = value;
        RaisePropertyChanged("StudentId");
    }
}

public string FirstName
{
    get { return _firstName; }
    set
    {
        _firstName = value;
        RaisePropertyChanged("FirstName");
    }
}
public string LastName
{
    get { return _lastName; }
    set
    {
        _lastName = value;
        RaisePropertyChanged("LastName");
    }
}

public string Student
{
    get { return string.Format("{0} {1}", FirstName, LastName); }
}

public bool PrintCertificate
{
    get { return _printCertificate; }
    set
    {
        _printCertificate = value;
        RaisePropertyChanged("PrintCertificate");
    }
}
public bool Select
{
    get { return _select; }
    set
    {
        _select = value;
        RaisePropertyChanged("Select");
    }
}
public int TestDateId
{
    get { return _testDateId; }
    set
    {
        _testDateId = value;
        RaisePropertyChanged("TestDateId");
    }
}
public string Rank
{
    get { return _rank; }
    set
    {
        _rank = value;
        RaisePropertyChanged("Rank");
    }
}

#region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        public void RaisePropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }

        #endregion

今私のXaml

  <xctk:CheckListBox Height="200" 
    ItemsSource="{Binding Path=ActiveStudents, Mode=TwoWay}"
    Name="ActiveStudents" 
    DisplayMemberPath="Student"
    ValueMemberPath="StudentID" 
    SelectedMemberPath="Select"    
    SelectedItem="{Binding SelectedStudent}"
    SelectedItemsOverride="{Binding SelectedStudentValue}"/>

<DataGrid  MaxHeight="200" MinHeight="200" Name="MyGrid"
        Grid.Row="1" Grid.Column="1" 
        VerticalAlignment="Top"
        HeadersVisibility="Column"
        AutoGenerateColumns="False" 
        AlternatingRowBackground="#F0EDF2"                                                             
        ItemsSource="{Binding GridDisplay}"   
        VerticalScrollBarVisibility="Auto" 
        CanUserAddRows="false">
    <DataGrid.GroupStyle>.....

これに加えて、チェックリストボックスで事前にチェックされている学生を決定するドロップダウンリストがあり、データグリッドに表示されます. この最後の部分は理解できると確信していますが、チェック リスト ボックスから選択した学生をデータ グリッドに表示することができません。

どんな助けでも大歓迎です。

4

1 に答える 1

0

CheckedListBox には ItemCheck イベントがあります。e.Index により、イベント内からどのアイテムがチェックされているか/チェックされていないかを確認します。また、e.CurrentValue と e.NewValue も確認する必要があります。

于 2013-11-10T01:50:10.457 に答える