{"id":2406,"date":"2014-10-16T21:08:42","date_gmt":"2014-10-16T21:08:42","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=2406"},"modified":"2014-10-16T21:08:42","modified_gmt":"2014-10-16T21:08:42","slug":"indenting-column-data-in-hierarchical-data-in-the-xamdatagrid","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/indenting-column-data-in-hierarchical-data-in-the-xamdatagrid\/","title":{"rendered":"Indenting column data in hierarchical data in the XamDataGrid"},"content":{"rendered":"<p><em>Before I start this post, let me just say I\u2019m using an old version of the Infragistics XamDataGrid for this post, version 10.3. Hence this may have been changed in subsequent releases, but as I have a legacy application to support, that\u2019s the version they\u2019re using.<\/em><\/p>\n<p>So in my previous blog posts on displaying hierarchical data within the XamDataGrid I demonstrated how to get the grid to look a little like a tree view, i.e. show the data in aligned columns etc. but I also mentioned that it wasn&#8217;t yet good enough as the child nodes are not indented.<\/p>\n<p>So let&#8217;s look at how we might indent the child nodes so that they look more like a tree view and differentiate between child nodes and parent nodes.<\/p>\n<p>What we want to do is change this <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/putridparrot.com\/blog\/wp-content\/uploads\/2014\/09\/XamDataGrid3.png\" alt=\"Before indentation\" \/><\/p>\n<p>to this<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/putridparrot.com\/blog\/wp-content\/uploads\/2014\/10\/XamDataGrid4.png\" alt=\"After indentation\" \/><\/p>\n<p>Here&#8217;s a reminder of how our XAML looked at the end of the previous post<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;igDP:XamDataGrid DataSource=&quot;{Binding}&quot; GroupByAreaLocation=&quot;None&quot; x:Name=&quot;grid&quot;\r\n   FieldPositionChanged=&quot;Grid_OnFieldPositionChanged&quot;&gt;\r\n   &lt;igDP:XamDataGrid.Resources&gt;\r\n      &lt;Style TargetType=&quot;{x:Type igDP:LabelPresenter}&quot;&gt;\r\n         &lt;EventSetter Event=&quot;SizeChanged&quot; Handler=&quot;EventSetter_OnHandler&quot;\/&gt;\r\n      &lt;\/Style&gt;\r\n   &lt;\/igDP:XamDataGrid.Resources&gt;\r\n\r\n   &lt;igDP:XamDataGrid.FieldLayoutSettings&gt;\r\n      &lt;igDP:FieldLayoutSettings ExpansionIndicatorDisplayMode=&quot;CheckOnDisplay&quot;\r\n         AutoGenerateFields=&quot;False&quot;\/&gt;\r\n   &lt;\/igDP:XamDataGrid.FieldLayoutSettings&gt;\r\n   &lt;igDP:XamDataGrid.FieldLayouts&gt;\r\n\r\n      &lt;igDP:FieldLayout Key=&quot;parent&quot;&gt;\r\n         &lt;igDP:FieldLayout.Fields&gt;\r\n            &lt;igDP:Field Name=&quot;Name&quot; \/&gt;\r\n            &lt;igDP:Field Name=&quot;Manages&quot; Visibility=&quot;Hidden&quot; \/&gt;\r\n         &lt;\/igDP:FieldLayout.Fields&gt;\r\n      &lt;\/igDP:FieldLayout&gt;\r\n\r\n      &lt;igDP:FieldLayout Key=&quot;child&quot;&gt;\r\n         &lt;igDP:FieldLayout.Settings&gt;\r\n            &lt;igDP:FieldLayoutSettings LabelLocation=&quot;Hidden&quot; \r\n                 DataRecordPresenterStyle=&quot;{StaticResource childDataRecordStyle}&quot;\/&gt;\r\n         &lt;\/igDP:FieldLayout.Settings&gt;\r\n         &lt;igDP:FieldLayout.Fields&gt;\r\n            &lt;igDP:Field Name=&quot;Name&quot;\/&gt;\r\n             &lt;igDP:Field Name=&quot;Manages&quot; Visibility=&quot;Hidden&quot; \/&gt;\r\n         &lt;\/igDP:FieldLayout.Fields&gt;\r\n      &lt;\/igDP:FieldLayout&gt;\r\n\r\n   &lt;\/igDP:XamDataGrid.FieldLayouts&gt;\r\n&lt;\/igDP:XamDataGrid&gt;\r\n<\/pre>\n<p>We&#8217;ve already used a value converter once, to align the columns, we&#8217;re going to use the same technique now to indent our cell data. Here&#8217;s the convert code<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic class ChildCellValueConverter : IValueConverter\r\n{\r\n   public object Convert(object value, Type targetType, object parameter, CultureInfo culture)\r\n   {\r\n      return value == null ? Binding.DoNothing : new Thickness((((int)value \/ 2) * 17), 0, 0, 0);\r\n   }\r\n\r\n   public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\r\n   {\r\n      throw new NotImplementedException();\r\n   }\r\n}\r\n<\/pre>\n<p>Now let&#8217;s implement the resource code in XAML<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;controls:ChildCellValueConverter x:Key=&quot;childCellValueConverter&quot; \/&gt;\r\n\r\n&lt;Style x:Key=&quot;childCellValueStyle&quot; TargetType=&quot;{x:Type igDP:CellValuePresenter}&quot;&gt;\r\n   &lt;Setter Property=&quot;Margin&quot; Value=&quot;{Binding NestingDepth, Converter={StaticResource childCellValueConverter}}&quot;\/&gt;\r\n&lt;\/Style&gt;\r\n<\/pre>\n<p>and finally we need to update the field layout (for the &#8220;child&#8221;) to add the following (within the Field &#8220;Name&#8221; element<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;igDP:Field.Settings&gt;\r\n   &lt;igDP:FieldSettings CellValuePresenterStyle=&quot;{StaticResource childCellValueStyle}&quot; \/&gt;\r\n&lt;\/igDP:Field.Settings&gt;\r\n<\/pre>\n<p>and there we have it. Now the child records indent.<\/p>\n<p><em>Note: Unfortunately the solution to displaying the child nodes offset from the parent nodes is not perfect. You may notice white space where text should be for some rows. If I come up with a solution I&#8217;ll update this post accordingly.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before I start this post, let me just say I\u2019m using an old version of the Infragistics XamDataGrid for this post, version 10.3. Hence this may have been changed in subsequent releases, but as I have a legacy application to support, that\u2019s the version they\u2019re using. So in my previous blog posts on displaying hierarchical [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[84,85],"tags":[],"class_list":["post-2406","post","type-post","status-publish","format-standard","hentry","category-infragistics","category-xamdatagrid"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=2406"}],"version-history":[{"count":7,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2406\/revisions"}],"predecessor-version":[{"id":2454,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2406\/revisions\/2454"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=2406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=2406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=2406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}