How can i treat my GridColumns in my FlexGrid as just strings?

Posted by: jacob.a.buchanan6.ctr on 28 July 2026, 5:41 pm EST

  • Posted 28 July 2026, 5:41 pm EST

    The issue I’m having is I essentially have a large collection of objects whose properties have been abstracted out to just objects, so their typing has been lost. I can see their values in my grid, but I cant sort the columns seemingly because they are treated as objects. This is the case with a standard DataGrid as well. I can, however, sort strings, so I was wondering if i could force these columns to be text/string based columns in my FlexGrid?

    It’s a bit difficult to describe our exact setup and the reasoning behind it, but the general idea and the issue can be expressed with a class like this:

    public class MyClass
    {
    	public MyClass(int someInt, string someString)
    	{
    		SomeIntProperty = someInt;
    		SomeStringProperty = someString;
    	}
    	public object? SomeIntProperty { get; }
    	public object? SomeStringProperty { get; }
    
    	public static ObservableCollection<MyClass> GetSampleObjects(int count)
    	{
    		List<MyClass> objects = [];
    		for (int i = 0; i < count; i++)
    		{
    			objects.Add(new MyClass(i, $"Some String {i]"));
    		}
    		return new ObservableCollection<MyClass>(objects);
    	}
    }

    And then in xaml just set up a basic FlexGrid with AllowSorting and ShowSort set to true. Then set it’s ItemsSource is set to MyClass.GetSampleObjects(500). You’ll notice it will show the int and string values in the table, but you can’t click the column header to sort the row.

    I could possibly convert the collection to strings in my code, but I was curious if this could be done directly like how the DataGrid has a DataTextGridColumn to treat it explicitly as a string.

  • Posted 29 July 2026, 8:06 am EST

    Hello,

    Unfortunately, there is no direct way to achieve this requirement in FlexGrid.

    As possible workarounds, you can either:

    • Expose additional properties that return the string representation of your ‘object’ properties and assign those properties to the ‘SortMemberPath’ of the corresponding ‘GridColumn’ (approach suggested by you), or
    • Handle the ‘CellTapped’ event of the FlexGrid and perform the sorting manually.

    For the second approach, we’ve attached a sample implementation for your reference: FlexGrid_Sample.zip

    Please let us know if this helps or if you have any further questions.

    Regards,

    Uttkarsh.

  • Posted 30 July 2026, 4:21 pm EST

    Hi Uttkarsh,

    The Short Version

    I realize I didn’t give you the full scope of the issue in my previous messages. Ultimately, I have a Dictionary<string, object> where each key represents a column name and the value array represents all the values for that column. I need to display this dynamically in a FlexGrid with built-in filtering/sorting enabled. In addition to the built-in grid filtering, I also have two custom spatial/selection filters applied from my ViewModel.

    The Long Version

    I was testing your idea along with several other approaches and kept running into roadblocks. I should have presented you with the full picture initially because our use case is a bit unique.

    This refactor was prompted by an upgrade from .NET Framework to .NET 9. We updated our C1 packages from v4.6.20251.877 to v9.0.20251.1133. We have a backend system that returns a Dictionary<string, object?> for a given dataset. Historically, we constructed a DataTable from this dictionary specifically so we could define the DataType for each column. Without specifying the data types, the FlexGrid misses out on the built-in sorting and filtering options (which was the issue I originally posted about).

    We ultimately need 3 forms of filtering to work in unison in our FlexGrid:

    1. Built-in Grid Filtering: The standard value/condition filtering provided by the FlexGrid UI.
    2. Filter by Extent: Each row has associated spatial Geometry. We have a button that filters the grid to only show rows whose geometry falls within a specific map extent.
    3. Filter by Selected: The grid’s row selection needs to be synced with geometry selection on our map. If the user toggles “Filter by Selected,” the grid should only display rows that are currently selected on the map.

    In our old .NET Framework setup, we had a C1FlexGrid bound to a DataView. This DataView contained all the fields from our dictionary, plus 3 additional fields: Geometry, IsVisible (set to true/false based on the map extent), and IsSelected (a pseudo two-way binding between the UI row selection and map selection). We handled the filtering by binding C1FlexGridFilterService.FlexGridFilter on the grid to a C1FlexGridFilter property in our ViewModel. We didn’t love this approach because it forced a WPF UI dependency into our ViewModel, but it worked.

    After updating to v9.0.20251.1133, the C1FlexGridFilter class seems to have been removed so a refactor we needed to get the tool working again. The documentation suggested using a C1DataCollection. I had high hopes for this because the filtering/grouping architecture seems ideal for our setup, but I just can’t get it working with our data. Here is what I’ve tried so far:

    1. C1DataCollection

      I created an AttributeRow class with a Dictionary<string, object?> Values property, an IsSelected boolean, and a Geometry property. In my XAML, I disabled AutoGenerateColumns. I listened to the ItemsSourceChanged event, grabbed the first row, and manually built the columns from the dictionary keys using this code:
    foreach (var kvp in firstRow.Values)
    {
        flexGrid.Columns.Add(new GridColumn() { Header = kvp.Key, Binding = $"Values[{kvp.Key}]" });
    }

    I could successfully apply my custom “Filter by Selected” and “Filter by Extent” logic by passing FilterPredicateExpressions into FilterAsync(). However, because the columns were bound to dictionary values, the FlexGrid couldn’t determine the underlying DataType. Consequently, I lost the ability to sort columns or use the FlexGrid’s built-in column filters.

    1. C1DataCollection

      I tried a very similar manual column-generation setup using DataRowView instead of my custom class.

      However, I hit the exact same issue where sorting and built-in filtering were disabled. I’m assuming this limitation is directly tied to creating the GridColumns manually rather than letting AutoGenerateColumns inspect a strongly typed schema?

    2. C1BindingListDataCollection with a DataTable

      Lastly, I tried reverting to our original DataTable setup, but instead passing dataTable.DefaultView into a C1BindingListDataCollection. I re-enabled AutoGenerateColumns, and finally, the native sorting and grid filtering worked again! To handle the custom map filters, I added the Geometry, IsVisible, and IsSelected columns back into the DataTable. My plan for the “Filter by Extent” option was to set the IsVisible boolean in the table based on my own spatial queries using the Row’s Geometry and then use a FilterOperationExpression on the IsVisible field. Similarly, for the IsSelected filtering, I would pass the SelectedItems collection to my ViewModel, but the grid seems to return a dynamic ItemWrapper class rather than the DataRowView itself. The issue with this setup is that it seems when I would modify one of the row values (IsVisible or IsSelected) it would reset my row selection. Maybe the ItemWrapper class sets its own bindings? These additional updates to the grid/UI were causing a lot of issues with maintaining that IsSelected value in-sync with the UI. I struggled to make this work, even though it felt like the closest solution.

    All of this is to say: I fear I have greatly overcomplicated this migration.

    To summarize: I have dynamic column data (Dictionary<string, object?>) that I need to display in a FlexGrid. I need native UI sorting/filtering, alongside the ability to apply two custom external filters (Extent and Selection) from my ViewModel.

    What is the recommended architectural approach for this in the .NET 9 FlexGrid? Any and all advice is greatly appreciated!

  • Posted 31 July 2026, 5:35 am EST

    Hi Jacob,

    Thank you for the detailed explanation of your requirements and for sharing the approaches you have already tested.


    We investigated your scenario and found that using an AttributeRow class together with C1DataCollection will always result in the same behavior because the data types are not explicitly defined in your Dictionary<string, object>. As a result, all values are treated as object, which prevents the grid from correctly identifying the underlying data types.


    Regarding your second approach, it appears to be a much better fit for your scenario. We implemented a similar solution by creating a DataTable from the Dictionary<string, object> with the appropriate column data types defined, and then assigning it to the FlexGrid’s ItemsSource by wrapping it in a C1BindingListDataCollection.

    With this approach, the native sorting and filtering functionality worked correctly.

    As for the SelectedItems collection returning a dynamic wrapper class (MyDynamicType) instead of the original DataRowView, this is expected behavior. C1BindingListDataCollection internally wraps the DataRowView objects in dynamic wrapper objects to provide its sorting and filtering functionality.

    However, you can still use these dynamic objects to get/set your data values using

    dynamic rowDynamicItem = flexGrid.Rows[flexGrid.CursorRange.Row].DataItem;
    rowDynamicItem.Geometry = "Hello World";

    Alternatively, you can use reflection to retrieve the underlying DataRowView object from the dynamic wrapper. You can then use this DataRowView to implement your existing logic, similar to your .NET Framework project.

    var type = rowDynamicItem.GetType();
    var propInfo = type.GetProperty("Item", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
    var dataRowView = propInfo.GetValue(rowDynamicItem) as DataRowView;
    Debug.WriteLine($"Getting Geometry via DataRowView: {dataRowView?.Row["Geometry"]}");

    Please refer to the attached sample project, which demonstrates how to work with the dynamic ItemWrapper (MyDynamicType) objects - FlexGrid_Sample_DataView.zip


    If you encounter any issues while implementing your existing features using this approach, please update the sample project to reproduce the problem and share it with us. This will help us investigate the issue further.

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels