Solved

Setting Datagrid Columns?

Posted on 2008-06-25
4
196 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

15 Experts available now in Live!

Get 1:1 Help Now