hide column(s) in windows datagrid

  • Thread starter Ignacio Martinez
  • Start date
I

Ignacio Martinez

Hey group!
I have worked with ASP.NET Webforms for quite a long time, and about a month
ago I started working with VB.NET Windows Forms.
And I found the Datagrid control to be a bit different from the Webforms
control.
Above all because I had to design Table And Column Styles, and I Don't know
how to make a Column invisible.
(following other option that's not width = 0).
I believe that if I set a MappingName for a column, this sets a relation
between the column and the Datatable Column Name.
But what If I want to hide the ID Column? and Can I just show the fields I
want instead of receiving all the columns from the Datasource? (Dataset in
this case)

I hope my english is clear enough.
thanx in advance
Ignacio.
 
C

Chris Botha

You have to add a TableStyle to the grid, then in the TableStyle, add
GridColumnStyle objects.
The easiest (I think) is, look in the properties of the grid for the
TableStyles Collection property. Go in there and add one. The mapping name
must be the name of your DataTable. Now inside that, look for the
GridColumnStyles, add a bunch of these and in this case the mapping name for
each is the column name. You can also do it programmatically. Hope it is
clear, as it is a bit complicated.
 
H

Hector Correa

Hola Ignacio,

As Chris mentioned, you need to use TableStyles to do
what you want to do. And indeed, it is more complicated
than it should.

Here is an example of a small class that I created to
save the properties of a grid to an XML file so that next
time the user launches the form the grid properties (e.g.
column width) are preserved:

http://www.gotdotnet.com/Community/UserSamples/Details.asp
x?SampleGuid=c70c9240-d404-4f5c-b2fc-45475ef1eeb0
 
I

Ignacio Martinez

Thanx for the answers.
I've done all the things you tell me to do.
The problem here is that tha datagrid doesn't respect the GrdColumnStyle
settings, let's say that my query returns 10 columns, and I just set 5
columns in the datagrid because I only want to show 5, and set the first
column width to 0. Well, not only the first column is shown, but I also get
all the columns from the query in the datagrid. It's like the tablestyle
setting is being bypassed.

I'm trying to find the way to get closer (without getting hurt in the
process) to the Datagrid Web Control, wich is much easier to use and set.

thanx for the answers!
Ignacio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top