3

I've been at this for a while now and cannot seem to figure out how to get the Eto.Forms TreeGridView Control to properly render. I'm trying to just add a few GridViewItem's at the moment and I just get a small gray bar at the top:

enter image description here

Here is my code:

        List<ITreeGridItem> treeGridItems = new List<ITreeGridItem>();
        foreach (var contentType in contentTypes)
        {
            treeGridItems.Add(new TreeGridItem(contentType.Name));
        }

        Content = new DocumentPage(new TreeGridView
        {
            DataStore = new TreeGridItemCollection(treeGridItems)

        }, new Padding(20));

I'm not even really sure where to start, I just want to get a tree with text to show for each node at the moment and I can't even do that.

The Pax Bisonica
  • 2,154
  • 2
  • 26
  • 45

1 Answers1

3

After a bit of trial and error I figured out how to use the tree view:

 var treeGridView = new TreeGridView
        {
            BackgroundColor = Colors.White
        };

        treeGridView.Columns.Add(new GridColumn
        {
            HeaderText = "Content Type",
            DataCell = new TextBoxCell(0)
        });

        treeGridView.Columns.Add(new GridColumn
        {
            HeaderText = "Create",
            DataCell = new CustomCell
            {
                CreateCell = r =>
                {
                    TreeGridItem item = r.Item as TreeGridItem;

                    ContentTypeTag tag = (ContentTypeTag)item.Tag;
                    var contentType = _siteManager.CurrentSite.ContentTypes.First(x => x.Name.Equals(tag.ClassName));

                    void Click(object btnSender, EventArgs btnArgs)
                    {
                        //Your Event
                    }

                    var button = new LinkButton
                    {
                        Style = "primary-link-btn",
                        Text = $"Create {contentType.Name.ToSentenceCase()}",
                        Command = new Command(Click)
                    };

                    return button;
                }
            }
        });

        treeGridView.Columns.Add(new GridColumn
        {
            HeaderText = "Show All",
            DataCell = new CustomCell
            {
                CreateCell = r =>
                {
                    TreeGridItem item = r.Item as TreeGridItem;

                    ContentTypeTag tag = (ContentTypeTag)item.Tag;
                    var contentType = _siteManager.CurrentSite.ContentTypes.First(x => x.Name.Equals(tag.ClassName));

                    void Click(object btnSender, EventArgs btnArgs)
                    {
                       //Your Event
                    }

                    var button = new LinkButton
                    {
                        Style = "primary-link-btn",
                        Text = $"Show All {contentType.Name.ToSentenceCase()}",
                        Command = new Command(Click)
                    };

                    return button;
                }
            }
        });

            var treeGridItemCollection = new TreeGridItemCollection();
            foreach (var contentType in _siteManager.CurrentSite.ContentTypes)
            {
                var item = new TreeGridItem
                {
                    Values = new string[] { contentType.Name.ToSentenceCase(), "Create", "Show All" },
                    Tag = new ContentTypeTag
                    {
                        ClassName = contentType.Name
                    }
                };

                treeGridItemCollection.Add(item);
            }

            treeGridView.DataStore = treeGridItemCollection;

You create the header columns to start and then create a TreeGridItemCollection and set the datastore to that. The values for each column of the row is set in a string array to the Values property of the TreeGridItem.

The Pax Bisonica
  • 2,154
  • 2
  • 26
  • 45
  • 1
    Ok so the part you didn't do at first was adding the GridColumns ! Thanks for answering :) I've also seen that you can use directly the TreeGridItem instead of TreeGridItemCollection to define the data (I don't know if there are drawbacks). – brainsandwich Jun 25 '18 at 14:36