Note that there are some explanatory texts on larger screens.

plurals
  1. PODataGrid Column XAML
    primarykey
    data
    text
    <p>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.</p> <p>Here is my XAML:</p> <pre><code>&lt;DataGrid Name="details" Margin="0,20,0,0" ItemsSource="{Binding}"&gt; &lt;/DataGrid&gt; </code></pre> <p>And this is the code behind it:</p> <pre><code>data = new DbLayer(); int cardNumId = (from dataCardNum in data.creditCards where dataCardNum.creditCardNumber == cardNum select dataCardNum.Id).First(); debits =new ObservableCollection&lt;Debit&gt;(( from billings in data.charges where billings.creditCardNumber.Id == cardNumId select billings).ToList()); DataContext = debits; </code></pre> <p>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.</p> <p>Here is my dataTemplate:</p> <pre><code>&lt;DataTemplate x:Key="debitShow" DataType="DataTemplate:MonthBill.Debit"&gt; &lt;DataGrid&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="amount" Binding="{Binding amount}"/&gt; &lt;DataGridTextColumn Header="charge date" Binding="{Binding chargeDate}"/&gt; &lt;DataGridCheckBoxColumn Header="charged" Binding="{Binding charged}"/&gt; &lt;DataGridTextColumn Header="store name" Binding="{Binding storeName}"/&gt; &lt;DataGridTextColumn Header="purchase date" Binding="{Binding debitDate}"/&gt; &lt;DataGridTextColumn Header="description" Binding="{Binding description}"/&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/DataTemplate&gt; </code></pre> <p>window xaml: </p> <p>Debit class(the key attribute is for the codefirst database creation):</p> <pre><code>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; } } </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload