0

GridControl の Devexpress の DataTemplate に CheckBox があります。Grid の boolean フィールドにバインドされています。カスタム リストにチェック済みアイテム (選択された行 ID) を追加しています。そしてチェックボックスのチェックを外すと、カスタムリストから項目が削除されます。そして最後にボタンのクリックで、ボタンのクリックでレコードを挿入しています。

問題: 初めてフォームを開いて CheckBox を使用して項目を選択すると、CheckBox の Checked イベントは発生しませんが、プロパティ変更イベントが発生します。INSERTボタンをクリックすると、アイテムが選択されていないと表示されます。しかし、他の行を選択して挿入をクリックすると、最初に選択したアイテムのみが挿入され、前と現在の両方は挿入されません。それは流れを逃します。なぜこれが起こるのですか?何か案が?

Infill.cs

public partial class Infill:INotifyPropertyChanged
    {
        public int InfillID { get; set; }
    //some other fields here
     private bool isChecked;
        public bool IsChecked { get { return isChecked; } set { SetField(ref isChecked, value, "IsChecked"); } }
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
        protected bool SetField<T>(ref T field, T value, string propertyName)
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }
   }

InfillForm.xaml

<dxg:GridControl Height="500"  Name="grdInfill" VerticalAlignment="Center">
           <dxg:GridControl.Columns>
                      <dxg:GridColumn  AllowEditing="True" Width="10">
                                  <dxg:GridColumn.CellTemplate>
                                        <DataTemplate>    
                                                 <CheckBox Name="chkSelect" Visibility="Hidden"  HorizontalAlignment="Center" IsChecked="{Binding Path=RowData.Row.IsChecked, Mode=TwoWay}"  Checked="CheckEdit_Checked" Unchecked="CheckEdit_Unchecked"/>
                                          </DataTemplate>
                                 </dxg:GridColumn.CellTemplate>
                       </dxg:GridColumn>
            <dxg:GridColumn FieldName="IsChecked" Header="Select"  />
<dxg:GridControl.View>
 <dxg:TableView  Name="grdInfillInner"  ShowTotalSummary="True" AutoWidth="True" DetailHeaderContent="True"  ShowIndicator="False" ShowGroupPanel="False" CellValueChanging="grdInfillInner_CellValueChanging">
  </dxg:TableView>
      </dxg:GridControl.View>
</dxg:GridControl>

InfillForm.xaml.cs

private void CheckEdit_Checked(object sender, RoutedEventArgs e)
        {
            e.Handled = ProcessItem(true);

        }

        private void CheckEdit_Unchecked(object sender, RoutedEventArgs e)
        {
            e.Handled = ProcessItem(false);

        }
     private bool ProcessItem(bool IsChecked)
        {
            bool result = false;
            Infill item = grdInfillInner.FocusedRow as Infill;
            if (IsChecked)
            {
                if (item != null)
                {
                    // DO STUFF HERE EXAMPLE ADD or REMOVE Item to a list, BASED on CHECKED or UNCHECKED!!!
                    int infillid = item.InfillID;
                    infillListIDs.Add(infillid);
                    result = true;
                }
            }
            else
            {
                if (item != null)
                {
                    if (infillListIDs.Contains(item.InfillID))
                    {
                        // if uncheked the checked item then remove from custom list
                        infillListIDs.Remove(item.InfillID);
                    }
                }
            }
            grdInfillInner.FocusedRowHandle = -1;
            return result;
        }
 protected void OpenWindow()
        {
            ReportPopup popup = new ReportPopup();
            popup.Owner = this;
            popup.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            popup.ShowDialog();

        }

private void MnuBtnInsert_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            //Delete existing and insert new items in table on every click
            BLL.DeleteAllInfillPO();
            if (infillListIDs.Count > 0)
            {

                for (int i = 0; i < infillListIDs.Count; i++) 
                {
                   //insert selected Checked items id in database
                    BLL.GetInfillIDAndInsertIntoInfillPO(infillListIDs[i]);
                }

                BtnView.Visibility = Visibility.Visible;
                BtnInsert.Visibility = Visibility.Hidden;
               //show report of inserted items
                OpenWindow();
            }
            else
            {
                MessageBox.Show("Please select item/s from list", "Select Option", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }

DataTemplate 内にある名前でチェックボックスを取得できないため、ブール値フィールドを追加し、データテンプレート内にある CheckBox にバインドしました。

助けて感謝!

4

2 に答える 2

0

<grid:GridColumn AllowEditing="True" Header="Completed"> <grid:GridColumn.CellTemplate> <DataTemplate> <CheckBox x:Name="PART_Editor" IsChecked="{Binding Path=Data.CompletedField}" HorizontalAlignment="Center" VerticalAlignment="Center"/> </DataTemplate> </grid:GridColumn.CellTemplate> </grid:GridColumn>

Binding Path に Data.Field を忘れずに追加してください。幸運を。

于 2014-04-01T12:39:01.780 に答える