Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

FlatTreeDataGridSource should contain a constructor that allows setting of Columns property #376

Open

Description

@NeilMacMullen

The docs contain this example code....

        Source = new FlatTreeDataGridSource<Person>(_people)
        {
            Columns =
            {
                new TextColumn<Person, string>("First Name", x => x.FirstName),
                new TextColumn<Person, string>("Last Name", x => x.LastName),
                new TextColumn<Person, int>("Age", x => x.Age),
            },
        };

However, it is NOT possible to use this approach if the type of data is not known in advance. For example, if we replace "Person" with a Row type where the number of columns may vary over time (although all rows in the table will have the same number of columns)

 public class Row(string [] rowItems)
 {
     public string this[int index]
     {
         //it's possible to get transient mismatches during update so
         //just return a dummy value if the binding is temporarily invalid
         get => index >= rowItems.Length ? string.Empty : rowItems[index];
     }
 }

then it would be desirable to write this kind of code...

var rows = result.EnumerateRows()
    .Select(items=> new Row(items))
    .ToArray();


  var columnList = new ColumnList<Row>();
  columnList.AddRange(
      result.ColumnDefinitions()
          .Select(col => new TextColumn<Row, string>(col.Name, r => r[col.Index]))
  );

 Source = new FlatTreeDataGridSource<Row>(rows,columnList) ;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions