11/05/2018, 10:11

Giúp em bài wpf application

Code MainWindow.xaml.cs Mã: using System;using System.Collections.Generic; 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 ...

Code MainWindow.xaml.cs
Mã:
using System;using System.Collections.Generic;
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;


namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            LoadData();
        }
        private void LoadData()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            var kq = from p in db.tbTests select p;
            dataGridSV.ItemsSource = kq;
        }
    }
}
Code MainWindow.xaml

Mã:
<Window x:Class="WpfApplication1.MainWindow"
        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:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
       
        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="10,15,0,0" TextWrapping="Wrap" Text="Mã sinh viên" VerticalAlignment="Top"/>
        <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="10,45,0,0" TextWrapping="Wrap" Text="Tên sinh viên" VerticalAlignment="Top"/>
        <TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="10,75,0,0" TextWrapping="Wrap" Text="Số điện thoại" VerticalAlignment="Top"/>


        <TextBox x:Name="txtMaSV" HorizontalAlignment="Left" Height="23" Margin="90,10,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120" DataContext="{Binding ElementName=dataGridSV, Path=SelectedItem}" Text="{Binding Path=MaSinhVien}" />
        <TextBox x:Name="txtTenSV" HorizontalAlignment="Left" Height="23" Margin="90,40,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120" DataContext="{Binding ElementName=dataGridSV, Path=SelectedItem}" Text="{Binding Path=TenSinhVien}" />
        <TextBox x:Name="txtSDT" HorizontalAlignment="Left" Height="23" Margin="90,70,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120" DataContext="{Binding ElementName=dataGridSV, Path=SelectedItem}" Text="{Binding Path=SoDienThoai}" />
        
        <DataGrid x:Name="dataGridSV" HorizontalAlignment="Left" Margin="10,98,0,0" VerticalAlignment="Top" Height="211" Width="497">
            <DataGrid.Columns>
                <DataGridTextColumn x:Name="colMaSV"
                                   Binding="{Binding Path= MaSinhVien}"
                                    Header="Mã sinh viên"
                                    >
                </DataGridTextColumn>
                <DataGridTextColumn x:Name="colTenSV"
                                   Binding="{Binding Path= TenSinhVien}"
                                    Header="Tên sinh viên"
                                    >
                </DataGridTextColumn>
                <DataGridTextColumn x:Name="colSDT"
                                    Binding="{Binding Path= SoDienThoai}"
                                    Header="Số điện thoại"
                                    >
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
    
    </Grid>
</Window>
DataClasses1.dbml



Giao dien truoc khi Start


Giao diện khi Start



Ở giao diện em tạo chỉ có 3 cột mà sau khi Start nó lại ra 6 cột, anh (chị) nào biết giúp em với.
0