Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding DataGrid to Collection<List>
    primarykey
    data
    text
    <p>Can a <code>DataGrid</code> be bound to a <code>Collection&lt;List&gt;</code> type?</p> <p>There are several questions on binding a <code>DataGrid</code> to a <code>Collection&lt;Collection&gt;</code> and it sort of worked for me too. But, I am looking specifically for <code>DataGrid</code> &lt;-- Binding --> <code>Collection&lt;List&gt;</code>.</p> <hr> <p>When I tried, the <code>List</code> is just getting displayed as an object on the <code>DataGrid</code> like:</p> <blockquote> <p><strong>Name</strong> <br> - System.Collections.Generic.List'1[System.Int32] <br> <strong>Value</strong> <br> Bob <br> 23 <br> 43000 <br> + System.Collections.Generic.List'1[System.Int32]</p> </blockquote> <p><br></p> <h2>How is a <code>List</code> different from a <code>Collection</code> in this case?</h2> <p>A <code>List</code> doesn't have identifiers for entries and hence entries in a List cannot be automatically grouped into columns in a <code>DataGrid</code>.</p> <h3>Example:</h3> <p>In <code>Collection&lt;List&gt;</code>: <br> entry1 contains the <code>List</code>: "Bob", 23, 43000 and <br> entry2 contains the <code>List</code>: "Alice", 42, 71000.</p> <p>Will I be able to use a <code>DataTemplate</code> for a <code>List</code> to get the following display? <br> <strong>Name | Age | Salary</strong> <br> Bob | 23 | 43000 <br> Alice | 42 | 71000</p> <p>Notice that strings Name, Age and Salary aren't part of the <code>Lists</code>. <hr></p> <h2>My plan</h2> <ol> <li>Bind the <strong>header</strong> row to a <code>List&lt;String&gt;</code> to get the column names in the <code>DataGrid's</code> header.</li> <li>Bind the <strong>remaining</strong> rows to <code>Collection&lt;List&gt;</code> to get the data populated in the <code>DataGrid</code>.</li> </ol> <p>Specifially, I'm wondering if I can put these 3 strings (Name, Age, Salary) in a <code>List&lt;String&gt;</code> and bind only the header row to it. The remaining rows of the <code>DataGrid</code> can be bound to Collection.</p> <p><strong>Is this even possible?</strong> <hr> Ideally, I would like to use <em>Infragistics'</em> <code>XamDataGrid</code>, but any solution to <code>DataGrid</code> will be a good starting point.</p> <p><hr></p> <h1>EDIT</h1> <p>Why don't I use <code>Collection&lt;Employee&gt;</code>? I would like to display only a <strong>subset of columns</strong> in the <code>DataGrid</code>.</p> <p>I have about 5 screens which display columns from 2 types <code>Employee</code> and <code>EmployeeDetails</code>. Both these types have about 100 different properties each and I'm only interested in displaying about 20 properties as columns on each screen. Hence, I'm creating a <code>List</code> for each <code>Employee</code>/<code>EmployeeDetails</code> object that contains only these 20 properties.</p> <p>The subset is defined at run-time by reading some config files. Hence, I can't statically define what I need to show.</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.
    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