Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:43:33+00:00 2026-06-11T02:43:33+00:00

I am using a DataGrid to show items from a database table, and I

  • 0

I am using a DataGrid to show items from a database table, and I am using EF CodeFirst so the database query automatically generates an object.

Here is my XAML:

<DataGrid Name="details" Margin="0,20,0,0" ItemsSource="{Binding}">
</DataGrid>

And this is the code behind it:

data = new DbLayer();
        int cardNumId = (from dataCardNum in data.creditCards
                         where dataCardNum.creditCardNumber == cardNum
                         select dataCardNum.Id).First();
        debits =new ObservableCollection<Debit>(( from billings in data.charges
                   where billings.creditCardNumber.Id == cardNumId
                   select billings).ToList());
        DataContext = debits;

That resolves in filling my DataGrid with all the information from my database. The only problem is that I have two columns that I don’t want to show. I tried to create a dataTemplate that will generate the grid with the columns I want, but when I bind it to the datacontext it showed no information.

Here is my dataTemplate:

<DataTemplate x:Key="debitShow" DataType="DataTemplate:MonthBill.Debit">
        <DataGrid>
            <DataGrid.Columns>
                <DataGridTextColumn Header="amount" Binding="{Binding amount}"/>
                <DataGridTextColumn Header="charge date" Binding="{Binding chargeDate}"/>
                <DataGridCheckBoxColumn Header="charged" Binding="{Binding charged}"/>
                <DataGridTextColumn Header="store name" Binding="{Binding storeName}"/>
                <DataGridTextColumn Header="purchase date" Binding="{Binding debitDate}"/>
                <DataGridTextColumn Header="description" Binding="{Binding description}"/>
            </DataGrid.Columns>
        </DataGrid>
    </DataTemplate>

window xaml:

Debit class(the key attribute is for the codefirst database creation):

class Debit
{        
    [Key]
    public int Id { get; set; }
    public int amount { get; set; }
    public string storeName { get; set; }
    public DateTime debitDate { get; set; }
    public DateTime chargeDate { get; set; }
    public string description { get; set; }
    public creditCard creditCardNumber { get; set; }
    public bool charged { get; set; }
}

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:43:34+00:00Added an answer on June 11, 2026 at 2:43 am

    If your objective is to display your data without the two columns that you don’t need, I would suggest taking the simpler approach of just specifying the columns of your grid explicitly:

    <DataGrid  ItemsSource="{Binding}" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="amount" Binding="{Binding amount}"/>
                <DataGridTextColumn Header="charge date" Binding="{Binding chargeDate}"/>
                <DataGridCheckBoxColumn Header="charged" Binding="{Binding charged}"/>
                <DataGridTextColumn Header="store name" Binding="{Binding storeName}"/>
                <DataGridTextColumn Header="purchase date" Binding="{Binding debitDate}"/>
                <DataGridTextColumn Header="description" Binding="{Binding description}"/>
            </DataGrid.Columns>
        </DataGrid>
    

    Notice the AutoGenerateColumns="False" attribute.

    I would only use a data template if I wanted to control the way the cells are rendered. If you are happy with the default presentation I think you don’t need a template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I show a join table in a datagrid in Flex using LCDS
I am using Datagrid control to populate list of items/contents. I want to show
I'm using the .NET4 WPF DataGrid to show a SQL table containing lots of
I'm working with WPF and EF. I'm using a Datagrid to show information. In
I am using a DataGrid in Expression Blend but I just need to show
I am using a DataGrid from the WpfToolkit. I have taken the Style resource
I am using a WPF DataGrid to display name-value pairs. SelectionUnit is set to
I'm using the WPF DataGrid control to show some details and a select button,
I'm trying to code a WPF 4.0 DataGrid that matches a database table, with
I am using the datagrid from WPF toolkit in a WPF windows application. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.