Solved

Setting Datagrid Columns?

Posted on 2008-06-25
4
202 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
[X]
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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linq, c# 8 50
Need help with another query 10 51
Read top line from CSV file 14 56
Health check of winows and webservces 5 49
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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