TreeGridView with Filter - C#

Hello,

I am trying to implemented a filter row to the Eto.Forms.TreeGridView we are using and I wonder if someone would have a sugesstion on how we could get a control like for example DB Broswer for SQLite is using.

How could someone get this kind of control? Using WPF we included the filter textbox into the header, but using Eto - really no clue on how to do that.

Kindest
Christian

I could also think of putting the filter in top of the column headers, maybe using an additional Grid or StackLayout that resizes when a ColumnWidthChanged event or something is firing. Is there an event that fires when the column header width was changed by a user?

Kindest
Christian

@curtisw,

do you have a small hint? Would be great.

Thanks
Christian

Hey @Christian_Hartz,

While there’s no way to add additional header rows, you could make the first row of the data a different type of control with a CustomCell.

For example:

  public class MyCustomCell : CustomCell
  {
    protected override Control OnCreateCell(CellEventArgs args)
    {
      if (args.Row == 0)
      {
        var filterTextBox = new TextBox { PlaceholderText = "Filter...", ShowBorder = false };
        // TODO: wire up filterTextBox to your filter logic
        return filterTextBox;
      }

      // TODO: create cell normally for data cells
      return new TextBox();
    }

    protected override string OnGetIdentifier(CellEventArgs args)
    {
      if (args.Row == 0)
        return "filter";
      return "data";
    }
  }

Hope this helps.

1 Like

As for a column width changed event, it’s not implemented yet but is scheduled to be done soon with RH-68493

The first solution is just working perfect.

image

I had to push the data by one index (rowheader index …) a.s.o. but this works great. And dont have to deal with the event handling.

I just wonder how the redraw of the grid will work while you are typing in the filtertextbox - because the data will be changing, right?

Many thanks once again.
Christian

This works. Thanks so much. Christian

25-05-2022_19-26-57

1 Like

I would also need this to be working - as I want to store the column width so the user doesn’t need to rearrange each column when reopening the TreeGridView. Is this supposed to work in Rhino 8 or would you have time to implement this a bit earlier?

Kindest
Christian

Just reading through the RH-68493. Did you already implemented the improvement? Is this available in Rhino WIP or will this be included in the next Rhino 7 release?

Kindest
Christian

Hey @Christian_Hartz, yes, this is available in 7.20 or later (the current service release candidate), so you should be able to give it a try. Sorry, usually we link the issue to the discourse post so it gets automatically notified but I forgot to do that with this one.

1 Like

Event is there - thanks for that - even a ColumnOrderChanged - awesome.

Just did the update, but now Eto.Wpf can not be found. Is there a change in the namespace?

#if ISWIN
if (this.ControlObject is Eto.Wpf.Forms.Controls.EtoDataGrid dataGrid)
{
    dataGrid.RowHeaderWidth = double.NaN;
    dataGrid.HeadersVisibility = System.Windows.Controls.DataGridHeadersVisibility.All;
    dataGrid.EnableRowVirtualization = true;
    dataGrid.LoadingRow += new EventHandler<System.Windows.Controls.DataGridRowEventArgs>(this.OnLoadingRow);
}
#elif ISMAC

#endif

Worked before - now it doesn’t.

I am using the NuGet RhinoCommon (7.20.22165.13001-rc) that includes the Eto.dll (Version 2.7.8200.29764).

Hey @Christian_Hartz, nothing has changed with Eto.Wpf, so perhaps something else is going on?

It is included in the RhinoWindows nuget package, not RhinoCommon.

1 Like

Alright - working fine now and the event is working.

Thank you once again. Christian

1 Like

I would like to change the filter row to the top of the TreeGridView by adding a StackLayout with as many TextBoxes as columns in the TreeGridView. To adjust the StackLayout I would need to listen to a horizontal scroll event or how would you @curtisw implement something like this?

A short video of the problem I am having right now.

Kindest
Christian

Also - I am trying to bind to the width of the GridColumn.

var binding = new BindableBinding<GridColumn, int>(gridColumn, c => c.Width);

But it seems GridColumn does not implement IBindable. Is there a way to bind to the width of a GridColumn?

Kindest
Christian

So - I think I am a step further, but now: How do I get rid of the scrollbar in the Scrollable? And its Windows only - @Curtis, maybe you have a pure Eto solution for that. Would be great.

Kindest
Christian

Alright - found a solution in the Windows OS implementation:

#if ISWIN
if (_scrollableFilterStackLayout.ControlObject is Eto.Wpf.Forms.EtoBorder border &&
    border.Child is System.Windows.Controls.ScrollViewer _scrollViewer)
{
    _scrollViewer.HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Hidden;
    _scrollViewer.VerticalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Hidden;
}
#elif ISMAC

// How does this look like on Mac OS????

#endif

Is it possible to set this via a style property of the Scrollable?

Eto.Style.Add<Eto.Wpf.Forms.Controls.ScrollableHandler>("AFScrollableFilterStyle", h =>
{
    ???
});

Kindest
Christian