Help me find Datagrid



  • Got it. DataGrid and TextBoxYou're making a point. TextBox and Datagrid Only the required line is visible.

    <DataGrid x:Name="сustomerDataGrid" Grid.Row = "2" Grid.Column = "2"   Grid.ColumnSpan = "3" HorizontalAlignment = "Stretch" VerticalAlignment = "Top" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" RowDetailsVisibilityMode="VisibleWhenSelected" MouseDoubleClick="сustomerDataGrid_MouseDoubleClick" LayoutUpdated="сustomerDataGrid_LayoutUpdated">
            <DataGrid.ToolTip>
                <ToolTip Background="#90004455">
                    <StackPanel>
                        <TextBlock Margin="3" Foreground="White">Редактирование: 2 шелчка по содержимому ячейки.</TextBlock>
                        <TextBlock Margin="3" Foreground="White">Удаление строки: выделить строку, нажать 'Delete'.</TextBlock>
                        <TextBlock Margin="3" Foreground="White">Сортировка: по нажатию заглавия столбца.</TextBlock>
                    </StackPanel>
                </ToolTip>
            </DataGrid.ToolTip>
            <DataGrid.Columns>
                <DataGridTextColumn x:Name="idCustomerColumn" Binding="{Binding IdCustomer}" Header="Id Заказчика" Width="Auto"/>
                <DataGridTextColumn x:Name="nameColumn" Binding="{Binding Name}" Header="Название организации" Width="Auto" CanUserSort="False"/>
                <DataGridTemplateColumn x:Name="locationColumn" Header="Местоположение" Width="Auto" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text = "{Binding Location}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate >
                    <DataGridTemplateColumn.CellEditingTemplate >
                        <DataTemplate >
                            <ComboBox SelectedItem = "{Binding Location}" ItemsSource = "{StaticResource Location}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn >
                <DataGridTextColumn x:Name="addressColumn" Binding="{Binding Address}" Header="Адрес" Width="Auto" CanUserSort="False"/>
                <DataGridTextColumn x:Name="phoneColumn" Binding="{Binding Phone}" Header="Телефон" Width="Auto" CanUserSort="False"/>
                <DataGridTextColumn x:Name="emailColumn" Binding="{Binding Email}" Header="Почта/E-mail" Width="Auto" CanUserSort="False"/>
                <DataGridTextColumn x:Name="representativeColumn" Binding="{Binding Representative}" Header="Представитель" Width="*" CanUserSort="False"/>
            </DataGrid.Columns>
        </DataGrid>
    

    Self-connection to base:

    ProjectAdministratorDataSet projectAdministratorDataSet = ((ProjectAdministratorDataSet)(this.FindResource("projectAdministratorDataSet")));
            ProjectAdministratorDataSetTableAdapters.СustomerTableAdapter projectAdministratorDataSetСustomerTableAdapter = new ProjectAdministratorDataSetTableAdapters.СustomerTableAdapter();
            projectAdministratorDataSetСustomerTableAdapter.Fill(projectAdministratorDataSet.Сustomer);
            System.Windows.Data.CollectionViewSource сustomerViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("сustomerViewSource")));
            сustomerViewSource.View.MoveCurrentToFirst();
    

    This is my search option, but nothing works:

    private void button2_Click_1(object sender, RoutedEventArgs e)
        {
    string login = textBox.Text;
            string Connection = @"Data Source=(local)\SQLEXPRESS; Initial Catalog=ProjectAdministrator; Integrated Security=True";
            string SelectQuery = "SELECT [IdCustomer] FROM [ProjectAdministrator].[dbo].[Customer] WHERE [IdCustomer] = '" + login + "'";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(SelectQuery, Connection);
            DataSet a = new DataSet();
            dataAdapter.Fill(a);
            сustomerDataGrid.ItemsSource = a.Tables[0].DefaultView;
    }
    


  • Decision found!

    private void button2_Click_1(object sender, RoutedEventArgs e)
        {
            if (radioButton.IsChecked == true)
            {
                string id = textBox.Text;
                SqlConnection cn = new SqlConnection(@"Data Source=(local)\SQLEXPRESS; Initial Catalog=ProjectAdministrator; Integrated Security=True");
                cn.Open();
                SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM Сustomer WHERE IdCustomer = '" + id + "'", cn);
                DataTable table = new DataTable();
                dataAdapter.Fill(table);
                if (table.Rows.Count == 0)
                {
                    MessageBox.Show("Такого значения несушествует");
                    cn.Close();
                }
                else
                {
                    DataSet a = new DataSet();
                    dataAdapter.Fill(a);
                    сustomerDataGrid.ItemsSource = a.Tables[0].DefaultView;
                    cn.Close();
                }
            }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2