Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Setting Datagrid Columns?

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

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 This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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