Search code examples
compact-framework.net-cf-3.5

How to select displayed columns in datagrid


I'm working on a .NET Compact Framework 3.5 app that includes a DataGrid. I've created a BindingSource using the designer and added the bindingsource as the source of the datagrid. It automatically created columns for every suitable property of my source object type, but I don't want to display all the properties.

How do I specify which columns to display and which ones to hide? I tried playing around with the TableStyles property of the datagrid (both in code and in designer), didn't seem to have any effect.


Solution

  • Figured it out. I had to add the following line of code in the form's constructor, right after InitializeComponent():

    myDataGrid.TableStyles[0].MappingName = myBindingSource.GetListName(null);
    

    Then I was able to change the datagrid's TableStyles property in order to modify the displayed columns as I please.