Can't Make Primary Key Column Invisible in DataGrid?

J

Joseph Geretz

Visual Studio 2005 / FX 2.0

I've got a datagrid which is bound to a BindingSource, pretty standard
stuff. Basically the grid is populated with every column from the underlying
table. I've got some columns marked as invisible, however the primary key
column keeps showing up. The best I can do is set this to width 5, but this
isn't what I want. Why can't I get this column to be invisible?

Thanks!

- Joe Geretz -
 
R

RobinS

I think I read this same problem in a posting a while back.
Try putting all the columns that are going to be invisible
*together*. No promises, but it's free to try it.

Robin S.
 
E

Earl

Here is what I found in your stocking today:

Probably the easiest technique is to set MappingType to Hidden on either the
dataset or the datatable BEFORE binding to the grid:

ds.YourTable.YourIDColumn.ColumnMapping = MappingType.Hidden;
-OR-

dt.Columns["YourID"].ColumnMapping = MappingType.Hidden;
 
J

Joseph Geretz

Thanks guys for your responses.

I played around with this a bit. It seems that the *first* column in the
grid can't be rendered invisible? Does that sound up to spec? I found that
simply shifting the column down to the second position caused it to go
invisible as defined. Then I tried to make the new column in the number one
position invisible, and found that it wouldn't cooperate.

Is this the defined behavior? Grid column #1 must be visible? In any case,
easy enough to work around.

Thanks,

- Joe Geretz -
 
E

Earl

Nope, it should not work that way. If you hide the column in the table, it
should not appear anywhere. If you are still showing columns after using the
MappingType.Hidden, that would tell me that you are doing a binding before
you set the Hidden property.
 
J

Joseph Geretz

Hi Earl,

What do you mean when you say 'hide the column in the table'? I'm not hiding
the column in the table; I'm setting Visible=False in the corresponding
column in the bound Grid.

Thanks,

- Joe Geretz -
 
E

Earl

As I noted in the earlier post, I'm referring to using MappingType.Hidden.
This allows you to hide the column on the dataset or datatable so it does
not appear when you bind the source to the grid.
 

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