{"id":1037,"date":"2020-04-26T08:29:04","date_gmt":"2020-04-26T07:29:04","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=1037"},"modified":"2020-04-26T08:29:04","modified_gmt":"2020-04-26T07:29:04","slug":"datagrid-from-class-list","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/charts-uwp-programming-in-c\/telerik-ui-for-uwp\/examples-telerik-ui-for-uwp\/datagrid-from-class-list","title":{"rendered":"DataGrid From Class List"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Simple Example<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">In the .xaml file<\/h5>\n\n\n\n<p>Add this to the start with the other xmlns lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    xmlns:controls=\"using:Microsoft.Toolkit.Uwp.UI.Controls\"\n    xmlns:prim=\"using:Microsoft.Toolkit.Uwp.UI.Controls.Primitives\"<\/code><\/pre>\n\n\n\n<p>Add this where you want your DataGrid:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n            &lt;!-- DATA GRID --&gt;\n            &lt;controls:DataGrid Canvas.Left=\"10\" Canvas.Top=\"530\" Width=\"780\" Height=\"730\" x:Name=\"DataGrid1\"\n                               ItemsSource=\"{x:Bind DataGridData1}\"\n                               AutoGenerateColumns=\"False\" \n                               CanUserReorderColumns=\"False\" CanUserResizeColumns=\"False\"\n                               CanUserSortColumns=\"False\" SelectionMode=\"Single\" &gt;\n\n                &lt;controls:DataGrid.Columns&gt;\n                    &lt;controls:DataGridTextColumn Header=\"Cat\" Binding=\"{Binding Category}\" Width=\"300\" IsReadOnly=\"True\" &gt;&lt;\/controls:DataGridTextColumn&gt;\n                    &lt;controls:DataGridCheckBoxColumn Header=\"Chk\" Binding=\"{Binding Value2}\" Width=\"40\" IsReadOnly=\"True\" &gt;&lt;\/controls:DataGridCheckBoxColumn&gt;\n                    &lt;controls:DataGridTextColumn Header=\"Value 1\" Binding=\"{Binding Value1}\" Width=\"200\" IsReadOnly=\"True\" &gt;&lt;\/controls:DataGridTextColumn&gt;\n                &lt;\/controls:DataGrid.Columns&gt;\n            &lt;\/controls:DataGrid&gt;<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">In the .cs file<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/-------------------------------\n\t\/\/----- CLASS FOR DATA GRID -----\n\t\/\/-------------------------------\n\tpublic class DataGridData\n\t{\n\t\tpublic string Category { get; set; }\n\t\tpublic double Value1 { get; set; }\n\t\tpublic bool Value2 { get; set; }\n\n\t\t\/\/----- CONSTRUCTOR -----\n\t\tpublic DataGridData (string Category, double Value1, bool Value2)\n\t\t{\n\t\t\tthis.Category = Category;\n\t\t\tthis.Value1 = Value1;\n\t\t\tthis.Value2 = Value2;\n\t\t}\n\t}\n\tpublic List&lt;DataGridData&gt; DataGridData1;<\/code><\/pre>\n\n\n\n<p>In your function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\/\/----- SET DATAGRID DATA -----\n\tDataGridData1 = new List&lt;DataGridData&gt;();\n\tDataGridData1.Add(new DataGridData(\"Cat0\", 1000, true));\n\tDataGridData1.Add(new DataGridData(\"Cat1\", 1001, false));\n\n\t\/\/Reload the datagrid\n\tDataGrid1.ItemsSource = DataGridData1;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Simple Example In the .xaml file Add this to the start with the other xmlns lines: Add this where you want your DataGrid: In the .cs file In your function:<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112,114],"tags":[],"class_list":["post-1037","post","type-post","status-publish","format-standard","hentry","category-examples-telerik-ui-for-uwp","category-examples-datagrid"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=1037"}],"version-history":[{"count":0,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/1037\/revisions"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=1037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=1037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=1037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}