0

I am fairly new to databases and Linq to SQL, but I have been able to find solutions to most of my problems through the internet and various books that i own. Yet I am having a problem when populating my datagrid, and I am unable to find anyone with the same problem or any work around for the problem.

Here is my code for my query and population of my textboxes and 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

All works as I wish except for when the datagrid is populated I get two unwanted columns at the end with the names of two of my three tables in the database. I'm not sure why the table names are being inserted here or how to get rid of them. Here is a link to what the datagrid looks like.

datagrid with extra columns of table names

Any help would be greatly appreciated.

"Invoices" and "Vehicle" are the extra columns. Also in the Vehicle column is what looks like some code.

jville
  • 3
  • 2

1 Answers1

0

In xaml when you define your datagrid, define the columns you want to see in your grid. Make sure autogenerate columns property is set to false.

<dg:DataGridTextColumn Header="Model" Binding="{Binding Path=Model}" />
Rick S
  • 6,476
  • 5
  • 29
  • 43
  • When I try this method I get an error that the "Items collection must be empty before using ItemsSource.", on the dgPastServices.itemsSource = makeSearch.Services – jville Jan 24 '14 at 16:13
  • Look at this: http://stackoverflow.com/questions/6882306/datagridtemplatecolumn-items-collection-must-be-empty-before-using-itemssource – Rick S Jan 24 '14 at 16:21
  • Absolutely wonderful...Thank you so much for pointing me to that example! Works like a charm now. I was forgetting some simple xaml code. – jville Jan 24 '14 at 18:56