Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 神秘的数据网格列_Wpf_Vb.net_Linq To Sql - Fatal编程技术网

Wpf 神秘的数据网格列

Wpf 神秘的数据网格列,wpf,vb.net,linq-to-sql,Wpf,Vb.net,Linq To Sql,我对数据库和Linq对SQL都是相当陌生的,但我已经能够通过互联网和我拥有的各种书籍找到解决我大部分问题的方法。然而,我在填充我的datagrid时遇到了一个问题,我找不到有相同问题的人,也找不到任何解决问题的方法 以下是我查询和填充文本框和数据网格的代码: Dim dbVehSearch As New VehicleDataClassesDataContext Dim makeSearch = (From v In dbVehSearch.Vehicles Where v.Vehic

我对数据库和Linq对SQL都是相当陌生的,但我已经能够通过互联网和我拥有的各种书籍找到解决我大部分问题的方法。然而,我在填充我的datagrid时遇到了一个问题,我找不到有相同问题的人,也找不到任何解决问题的方法

以下是我查询和填充文本框和数据网格的代码:

Dim dbVehSearch As New VehicleDataClassesDataContext

    Dim makeSearch = (From v In dbVehSearch.Vehicles Where v.VehicleId = CStr(txtVehID.Text)).SingleOrDefault()
    Dim bolExists As Boolean = If(makeSearch Is Nothing, True, False)

    If bolExists = False Then
        'txtMake.Text = makeSearch.FirstOrDefault.ToString
        txtMake.Text = makeSearch.Make
        txtModel.Text = makeSearch.Model
        txtModelYear.Text = makeSearch.ModelYear
        txtEngine.Text = makeSearch.Engine
        txtOilFilter.Text = makeSearch.OilFilter
        txtQts.Text = makeSearch.QtsAmt
        dgPastServices.ItemsSource = makeSearch.Services

    Else
        txtMake.Text = vbNullString
        txtModel.Text = vbNullString
        txtModelYear.Text = vbNullString
        txtEngine.Text = vbNullString
        txtOilFilter.Text = vbNullString
        txtQts.Text = vbNullString
        dgPastServices.ItemsSource = Nothing
    End If
除填充datagrid外,所有操作都按我的意愿进行,我在最后得到两个不需要的列,其中两个是数据库中三个表中的两个表的名称。我不知道为什么要在这里插入表名,或者如何删除它们。这里有一个指向datagrid的链接

任何帮助都将不胜感激


“发票”和“车辆”是额外的列。车辆列中还有一些代码。

在xaml中定义数据网格时,请定义希望在网格中看到的列。确保“自动生成列”属性设置为false

<dg:DataGridTextColumn Header="Model" Binding="{Binding Path=Model}" />


您的服务类中是否定义了发票和车辆?唯一的连接是它们在数据库中的关系。当我尝试此方法时,我得到一个错误,即“在使用ItemsSource之前,Items集合必须为空。”,关于dgPastServices.itemsSource=makeSearch.ServicesLook:非常好……非常感谢您为我指出了这个例子!现在很有魅力。我忘记了一些简单的xaml代码。