Tuesday, August 18, 2015

WPF GridCOntrol Get to Cell content in Master-Detail


           var hPanel = VisualTreeHelpers.FindChild<HierarchyPanel>(AssociatedObject);
            if (hPanel == null) return;
            
            var listOfRowAndCell= new List<Tuple<bool,int, List<Tuple<object, string>>>>();
            foreach (var hpChild in hPanel.Children)
            {
                var row = hpChild as GridRow;
                if (row == null) continue;
                var sviPanel = VisualTreeHelpers.FindChild<StackVisibleIndexPanel>(row);
                if (sviPanel == null) continue;
 
                var list= new List<Tuple<object, string>>();
                foreach (var child in sviPanel.Children)
                {
                   var cellContentPresenter = child as GridCellContentPresenter; // now we got to cell level
                   if (cellContentPresenter == null) continue;
                   var cell = cellContentPresenter.Element as DevExpress.Xpf.Grid.CellEditor;
                   if (cell == null) continue;

                    // Store Visible Text Value for later Validation
                    var ev = cell.Edit.EditValue;
                    var fn = cell.Column.FieldName;
                   list.Add(new Tuple<object, string>(ev,fn));
                }

                if (row.RowDataContent == null || row.RowDataContent.DataContext == null  || row.RowDataContent.DataContext as RowData==null) continue;
                int rh = (row.RowDataContent.DataContext as RowData).RowHandle.Value;
                listOfRowAndCell.Add(new Tuple<bool,int, List<Tuple<object, string>>>(IsMasterRow(row),rh,list));
            }

No comments: