Search code examples
c#gridvieweto

Numeric Eto Grid cell?


How do you create a numeric column (ideally integer) in an Eto forms GridView?

Below is my code for two string columns

stats.Columns.Add(new GridColumn
{
    DataCell = new TextBoxCell { Binding = Binding.Property<RulesDocAdapter, string>(r => r.Name) },
    HeaderText = "Name"
});

stats.Columns.Add(new GridColumn
{
     DataCell = new TextBoxCell { Binding = Binding.Property<RulesDocAdapter, string>(r => r.Abbreviation) },
     HeaderText = "Abbreviation"
});

Solution

  • To use different columns, you can convert the integer property to a string using the Convert() extension on the property binding, like so:

    Binding.Property((RulesDocAdapter r) => r.IntProperty).Convert(v => v.ToString(), s => { int i = 0; return int.TryParse(s, out i) ? i : -1; })