Solved

Setting Datagrid Columns?

Posted on 2008-06-25
4
199 Views
Last Modified: 2010-04-15
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.
0
Comment
Question by:directxBOB
  • 2
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 21864173
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
 

Author Comment

by:directxBOB
ID: 21864328
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 21865006
Another possibility is to query (sql) only the fields you want to show in your datagrid
0
 

Author Comment

by:directxBOB
ID: 21872523
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now