Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting Datagrid Columns?

Posted on 2008-06-25
4
Medium Priority
?
205 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 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