F
F
FAwafawf12122021-06-21 06:25:53
C++ / C#
FAwafawf1212, 2021-06-21 06:25:53

How to exclude row in datagrid?

How to exclude row from datagrid output?
I have a datagrid where the user double-clicks to select a row from an opened window, after which the window closes and his selection is counted. He selects one from the list of printers. but the problem is that the user can select the same one several times, so I want that if in my table (which contains already selected printers), there are matches with those that are in full (the table where they are all presented ). Then these lines should be removed from the search. I spent a few days and roughly threw it, as it can be according to my logic, but I still can’t find much.
As I think:
1) The method is loaded during the loading of the window, where the user will select a line.
2) Two variables in this method, the first is responsible for all printers, and the second is for the selected ones, I declare them
3) there is a comparison and if in all printers, I find matches, then I remove these printers from the final result
4) I display data in datagrid
here is the c# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Shapes;

namespace YchetApparatov
{
  public partial class PrinterListWindow : Window
    {

        public static int SelectPrinterInt;
        public PrinterListWindow()
        {
            InitializeComponent();
            SelectPrinterInt = 0;
        }

 private void DGPrinterViev_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
  var printertable = NormApparatYchetEntities2.GetContext().PrinterTable.ToList(); // в printertable все принтеры которые есть
            var naborinprinter = NormApparatYchetEntities2.GetContext().ComplectTable.ToList(); // в ComplectTable содержатся все принтеры, которые были использованы и которые я не -хочу видеть в datagrid
            var currentItemNabor = (ComplectTable)((FrameworkElement)sender).DataContext;           
            var currentItem = (PrinterTable)((FrameworkElement)sender).DataContext;
            if (currentItem.IdPrinter == currentItemNabor.IdPrinterInComplect )
            {

            }
            SelectPrinterInt = currentItem.IdPrinter;
            this.Close();
        }
    }  
}


here is the XAML

<Window x:Class="YchetApparatov.PrinterListWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:YchetApparatov"
        mc:Ignorable="d"
        Title="PrinterListWindow" Height="720" Width="1280">
    <Grid Margin="0,97,0,34">
        <Grid.RowDefinitions>
        </Grid.RowDefinitions>
        <DataGrid x:Name="DGPrinterViev" AutoGenerateColumns="False" IsReadOnly="True" Margin="0,-3,0,126"
              ItemsSource="{Binding Source}" SelectedItem="{Binding SelectedRow}" >
            <DataGrid.ItemContainerStyle>
                <Style TargetType="DataGridRow">
                    <EventSetter Event="MouseDoubleClick" Handler="DGPrinterViev_MouseDoubleClick"/>
                </Style>
            </DataGrid.ItemContainerStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Header="Модель принтера" Binding="{Binding ModelPrinter}" ></DataGridTextColumn>
                <DataGridTextColumn Header="Цвтеной или ЧБ" Binding="{Binding ColorOrBW}" ></DataGridTextColumn>
                <DataGridTextColumn Header="Скорость печати в минуту" Binding="{Binding SkorostPechati}" ></DataGridTextColumn>
                <DataGridTextColumn Header="Инвентарный номер принтера" Binding="{Binding InventarNomerPrinter}" ></DataGridTextColumn>
                <DataGridTextColumn Header="Серийный номер принтера" Binding="{Binding SeriyNomerPrinter}" ></DataGridTextColumn>
                <DataGridTextColumn Header="Дата прихода принтера" Binding="{Binding DataPrihodaPrinter}" ></DataGridTextColumn>
                <DataGridTextColumn Header="Дата списания принтера" Binding="{Binding DataSpisanPrinter}" ></DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="Очистить" HorizontalAlignment="Left" Margin="0,-30,0,0" VerticalAlignment="Top" Width="75"/>
        <TextBox HorizontalAlignment="Left" Height="22" Margin="88,-30,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="165"/>
        <Label Content="Фильтр" HorizontalAlignment="Left" Margin="0,-55,0,0" VerticalAlignment="Top" Height="25" Width="63"/>
        <Label Content="Поиск" HorizontalAlignment="Left" Margin="88,-55,0,0" VerticalAlignment="Top" Height="25" Width="63"/>

    </Grid>
</Window>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question