Results 1 to 2 of 2

Thread: Try to bind DataTable to DataGrid and filter it in best practice

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Aug 2018
    Posts
    3
    Rep Power
    0

    Try to bind DataTable to DataGrid and filter it in best practice

    I think the best way to do so it only uses the MainWindow.xaml without write code in C# in that file.
    So I opened a new class named HeaderGridView.cs and try to bind from there... I have no Idea what Am I doing wrong

    I have no error this bind just to nothing...

    And what it the best practice to use the filter (My Idea is to create one method in HeaderGridView.cs and to Attach to every TextBox and DatePicker by action every time the value change)
    How can I do it?


    MainWindow.xaml
    Code:
    <Window x:Class="ReportGenerator.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:ReportGenerator"
            xmlns:model="clr-namespace:MilBatDBModels;assembly=MilBatDBModels"
            xmlns:db="clr-namespace:DataBaseManager;assembly=DataBaseManager"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
            <StackPanel>
                <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                    <Label>???? ??? :</Label>
                    <TextBox MinWidth="50" ></TextBox>
                </StackPanel>
                <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                    <Label>???? ????? :</Label>
                    <TextBox MinWidth="50"></TextBox>
                </StackPanel>
                <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                    <Label>???? Batch :</Label>
                    <TextBox MinWidth="50" ></TextBox>
                </StackPanel>
                <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                    <Label >????? ????? :</Label>
                    <DatePicker ></DatePicker>
                    <Label>????? ????? :</Label>
                    <DatePicker></DatePicker>
                </StackPanel>
    
    
                <DataGrid x:Name="HeaderDataGrid" IsReadOnly="True" SelectionMode="Single" ItemsSource="{Binding HeaderGridView.HeaderTable}">
                </DataGrid>
            </StackPanel>
        </Grid>
    </Window>
    Code:
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    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 FastMember;
    using MilBatDBModels;
    using static DataBaseManager.PulserBaseManager;
    namespace ReportGenerator
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
            
        }
    }





    HeaderGridView.cs

    Code:
    using FastMember;using MilBatDBModels;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Controls;
    using static DataBaseManager.PulserBaseManager;
    namespace ReportGenerator
    {
        public class HeaderGridView
        {
            public DataTable HeaderTable { get; set; }
    
    
            public HeaderGridView() {
    
    
                HeaderTable = new System.Data.DataTable();
                List<HeaderResult> headerList = PulserBaseManagerInstance.GetHeaderResults();
                using (var reader = ObjectReader.Create(headerList))
                {
                    HeaderTable.Load(reader);
                }
                //HeaderDataGrid.DataContext = headerTable;
            }
            public void RunFilterAction(object sender, SelectionChangedEventArgs e)
            {
    
    
            }
    
    
        }
    }

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Aug 2018
    Posts
    5
    Rep Power
    0
    I have always been working with an ObservableCollection<T> sometimes with and sometimes without the Nuget extension Reactive Properties. Before filtering I have created a backup of the original items and then I removed those which had not fulfilled the criteria of the search string. As long as the ObservableCollection contained no nested array I used a generic method to create a DataTable from the ObservableCollection.

Similar Threads

  1. MVVM in Practice
    By DoJa in forum Windows Presentation Foundation (WPF)
    Replies: 3
    Last Post: 01-02-2017, 1:37 PM
  2. Question Best Practice
    By Pottsy in forum C# General Discussion
    Replies: 2
    Last Post: 09-04-2016, 10:38 PM
  3. How to bind a result of condition to a combobox?
    By Socarsky in forum Windows Forms
    Replies: 10
    Last Post: 04-02-2014, 2:48 AM
  4. Replies: 8
    Last Post: 12-01-2012, 1:12 AM
  5. Question Copy from datatable to new datatable
    By charlie20 in forum Windows Forms
    Replies: 2
    Last Post: 09-06-2012, 4:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •