Setting Datagrid Columns?

I am trying to set the Columns for my datagrid (Winfoms Compact Framework). I can't seem to see a way to set this up.

The issue is that I am populating a DataTable from a webservice, and then in the code I bind it to the DataGrid. There are a few columns in this Datatable that I don't want to show, any ways to edit this? The datasource is not populate in the designer thus I am limited a little.
directxBOBAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DhaestConnect With a Mentor Commented:
Here is an example of hiding columns (width = 0), using a table style:


    DataTable table; 
    
    DataGridTableStyle style = new DataGridTableStyle(); 
    style.MappingName = table.TableName; 
    
    DataGridTextBoxColumn column = new DataGridTextBoxColumn(); 
    column.MappingName = table.Columns[0].ColumnName; 
    column.Width = 0; 
    //Hide 
    
    style.GridColumnStyles.Add(column); 
    
    column = new DataGridTextBoxColumn(); 
    column.MappingName = table.Columns[1].ColumnName; 
    column.Width = 50; 
    //Show 
    
    this.DataGrid1.TableStyles.Clear(); 
    this.DataGrid1.TableStyles.Add(style); 

Open in new window

0
 
directxBOBAuthor Commented:
Ah that's what I was missing so basically I add styles for each column and set the width. Surely there must be an easier way of just having certain Columns?
0
 
DhaestCommented:
Another possibility is to query (sql) only the fields you want to show in your datagrid
0
 
directxBOBAuthor Commented:
Unfortunately it's going over a webservice, which means I have no control on the dataset coming back and no control on the webservice.

Cheers
0
All Courses

From novice to tech pro — start learning today.