Beispiel #1
0
 private void AddNewColumnToDataGrid(string headerName, string bindingProperty)
 {
     DtGrid.Columns.Add(new DataGridTextColumn {
         Header = headerName, Binding = new Binding(bindingProperty)
     });
     ButtonMenuContentItemList.Add(new DataGridColumnPropertyItem {
         HeaderName = headerName, IsChecked = true
     });
     SearchPropertyItemList.Add(new DataGridColumnPropertyItem {
         HeaderName = headerName, IsChecked = true
     });
 }
Beispiel #2
0
        private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e)
        {
            ButtonMenuContentItemList.Clear();
            SearchPropertyItemList.Clear();
            ButtonMenuContentItemList.Add(new DataGridColumnPropertyItem {
                HeaderName = "Deselect All", IsChecked = true
            });

            foreach (DataGridColumn d in DtGrid.Columns)
            {
                ButtonMenuContentItemList.Add(new DataGridColumnPropertyItem {
                    HeaderName = d.Header.ToString(), IsChecked = true
                });
                SearchPropertyItemList.Add(new DataGridColumnPropertyItem {
                    HeaderName = d.Header.ToString(), IsChecked = true
                });
            }


            if (DtGrid.DataContext is CustomerViewModel)
            {
                AddNewColumnToDataGrid("Customer Rank", "CustomerRank.Name");

                SearchPropertyItemList.RemoveAt(4); //Remove address1
                SearchPropertyItemList.RemoveAt(4); //Remove address2
                SearchPropertyItemList.Insert(4, new DataGridColumnPropertyItem {
                    HeaderName = "Address"
                });
            }

            if (DtGrid.DataContext is CustomerRankViewModel)
            {
                AddNewColumnToDataGrid("Number of Customers", "Customers.Count");
            }

            if (DtGrid.DataContext is CategoryViewModel)
            {
                AddNewColumnToDataGrid("Number of Products", "Products.Count");
            }

            if (DtGrid.DataContext is ProductViewModel)
            {
                AddNewColumnToDataGrid("Category", "Category.Name");
            }

            if (DtGrid.DataContext is GoodsReceiptViewModel)
            {
                AddNewColumnToDataGrid("Items Count", "ReceiptDetails.Count");
                AddNewColumnToDataGrid("Purchased In Store", "Store.Name");
            }

            var context = (DataContext as ICRUDViewModel);

            if (context.DtGridProperties == "Default")
            {
                context.DtGridProperties = "";
                foreach (var item in DtGrid.Columns)
                {
                    context.DtGridProperties += item.Header + "=true;";
                }
            }
        }