Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
325
RowChanged Event do not Work, in XamGrid
posted

Hello,

I have a Problem,  I want to get the RowChanged Event of Datatable  binding XamGrid.

but After Changing DataRow, RowChanged Event do not Work.

I don't know what is problem. That is my code, Below.

First Column is Checkboxcolumn. If User check cell in Checkboxcolumn, I get the checked row count and checked row data but RowChanged Event do not work.

I need your Help.

 

using System;

using System.Collections.Generic;

using System.Collections;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using System.ComponentModel;

using System.Data;

using System.Windows.Markup;

using Microsoft.Win32;

using Infragistics.Controls.Grids;

using Dsme.Ebms.Interface.DBManager;

 

//Excel Export를 위한 References

using Infragistics.Windows.DataPresenter.ExcelExporter;

using Infragistics.Documents.Excel;

using System.IO;

 

namespace TestPresentation

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        DataSet oDataSet;

      

        public MainWindow()

        {

            InitializeComponent();

            setGrid();

            dgdDisplay.AutoGenerateColumns = false;

            dgdDisplay.EditingSettings = new EditingSettings { AllowEditing = EditingType.Hover };

            DataContext = new MainViewModel();

        }

 

        private void btnSrch_Click(object sender, RoutedEventArgs e)

        {

            DBAgent _oDBAgent = new DBAgent();

            _oDBAgent.Open("dweduc", "bdoa", "manager");

 

            Object[] _aParam = new Object[] { "BDOA", "6046", "P", "E", "", "1','3" };

            // "oDataSet" is Select Result, Oracle Table

            oDataSet = _oDBAgent.ExecuteSaveViaFDOAS00L("BDOA", "selEquipTagHead2", _aParam);

            oDataSet.Tables[0].Columns.Add("SEL", typeof(bool));

            foreach (DataRow _oRow in oDataSet.Tables[0].Rows)

            {

                _oRow["SEL"] = false;

            }

            (DataContext as MainViewModel).Data = oDataSet.Tables[0];

            dgdDisplay.ItemsSource = (DataContext as MainViewModel).Data.DefaultView;

           

            _oDBAgent.Close();

        }

 

        private void setGrid()

        {

            CheckBoxColumn oSEL = new CheckBoxColumn { Key = "SEL", HeaderTemplate = CreateHeaderTemplate("선택"), IsSummable = false };

            TextColumn oPROJ_NO = new TextColumn { Key = "PROJ_NO", HeaderTemplate = CreateHeaderTemplate("공사번호"), IsReadOnly = true };

            TextColumn oBOM_CLSF = new TextColumn { Key = "BOM_CLSF", HeaderTemplate = CreateHeaderTemplate("BOM구분"), IsReadOnly = true };

            TextColumn oDSGN_SMBL = new TextColumn { Key = "DSGN_SMBL", HeaderTemplate = CreateHeaderTemplate("조직"), IsReadOnly = true };

            TextColumn oDSGN_APPL = new TextColumn { Key = "DSGN_APPL", HeaderTemplate = CreateHeaderTemplate("분야"), IsReadOnly = true };

            TextColumn oBOM_NO = new TextColumn { Key = "BOM_NO", HeaderTemplate = CreateHeaderTemplate("BOM NO."), IsReadOnly = true };

            TextColumn oBOM_DESC = new TextColumn { Key = "BOM_DESC", HeaderTemplate = CreateHeaderTemplate("BOM DESC."), IsReadOnly = true };

            dgdDisplay.Columns.Add(oSEL);

            dgdDisplay.Columns.Add(oPROJ_NO);

            dgdDisplay.Columns.Add(oBOM_CLSF);

            dgdDisplay.Columns.Add(oDSGN_SMBL);

            dgdDisplay.Columns.Add(oDSGN_APPL);

            dgdDisplay.Columns.Add(oBOM_NO);

            dgdDisplay.Columns.Add(oBOM_DESC);

        }

       

        public DataTemplate CreateHeaderTemplate(string sColHeader)

        {

            string template =

                @"<DataTemplate

                    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""

                    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">

                  

                    <StackPanel>

                                <TextBlock TextWrapping = ""Wrap"" Text=""" + sColHeader + @""" />

                    </StackPanel>

               

                </DataTemplate>";

 

            return XamlReader.Parse(template) as DataTemplate;

        }

 

        private void chkSelAll_Click(object sender, RoutedEventArgs e)

        {

            (DataContext as MainViewModel).CheckUncheckAll((bool)(sender as CheckBox).IsChecked);

            Console.WriteLine(string.Format("Checked LINE Count : ({0})", (DataContext as MainViewModel).AllSelectedCount));

        }

    }

 

    public class MainViewModel : INotifyPropertyChanged

    {

        int selectedCount;

        public MainViewModel()

        {

            Data = new DataTable();

            Data.RowChanged += new DataRowChangeEventHandler(Row_Changed);

            Data.AcceptChanges();

            AllSelectedCount = 0;

        }

 

        private void Row_Changed(object sender, DataRowChangeEventArgs e)

        {

            int temp = 0;

            foreach (DataRow r in ((DataTable)sender).Rows)

            {

                if ((bool)r.ItemArray[0])

                    temp++;

            }

            AllSelectedCount = temp;

        }

 

        public void CheckUncheckAll(bool check)

        {

            foreach (DataRow r in Data.Rows)

            {

                r["SEL"] = check;

                r.AcceptChanges();

            }

            Data.AcceptChanges();

        }

 

        public int AllSelectedCount

        {

            get

            {

                return selectedCount;

            }

            set

            {

                selectedCount = value;

                if (PropertyChanged != null)

                {

                    PropertyChanged(this, new PropertyChangedEventArgs("AllSelectedCount"));

                }

            }

        }

 

        public DataTable Data { get; set; }

 

        public event PropertyChangedEventHandler PropertyChanged;

    }

}