Can I define in datatable hidden columns?


I have datatable which is bound to grid.
In addition, this datatable is stored on server side and used to retrieve properties on server side as well.

Now I need to add to select sql 1 additional property:
this property will be used only on business logic side (so no need to render it to client).
But once I addit to sql - it's automatically displayed in grid.

I know how to make the property hidden by GridColumn.Hidden = true, but don't know the answers to the following questaions:

The questions are:
1. Can I define in datatable that column should not be bounded (so that it won't be rendered to client)? - the preferable option since I am chanign business logic and don't want grid be aware of that
2. Can I define in datagrid that column should not be bounded (so that it won't be rendered to client)?
3. Can I define in datatable that column should be hidden (so that it will be rendered to client but won't be dispalyed in grid)?
4. I feel somethign is wrong in my design: I am changing sql, and this requires changing grid as well (unless you find a solution to question 1). What is wrong? What's the right design for such cases?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1. No...

2. Yes...

3. No

4. The correct design in most cases is to setup what is displayed on your grid manually so that when SQL changes the grid does not.

You are talking about Datagrids so I presume you are using v1.1

To hide a column without manually setting up the grid's columns you can just do the following

DataGrid1.Columns[6].visible = false; //Where  is the index of your column.

I prefer to setup the columns manually, the easiest way it to right click your datagrid and go to [Property Builder]

Select columns and add [Bound Column]
Data Field = The field name in the data table and Header text is obvious isn't it ;)

You can then arrange them easily enough. You can also change the visibility from here as well.

Let me know if you are using .net 2.0 because it is completely different
netformxAuthor Commented:
Actually I am using infragistics grid, and 1.1 and I am setting column manually (at least I was thinking so):

UltraGridColumn Col1 = UltraWebGrid1.Columns.FromKey(Project.COLUMN_FIELD_NAME);
Col1.HeaderText = NfxConsts.Header_ProjectName;
Col1.Width = Unit.Percentage(NfxConsts.ColumnSize_ProjectName);
UltraGridColumn Col2 = UltraWebGrid1.Columns.FromKey(Project.COLUMN_FIELD_DESCRIPTION);
Col2.HeaderText = NfxConsts.Header_ProjectDescription;
Col2.Width = Unit.Percentage(NfxConsts.ColumnSize_ProjectDescription);


and I bind in UltraWebGrid1_DataBinding event:
UltraWebGrid1.DataSource = userProjects;

How can I change the code not to be dependant in sql changes? (I prefer working with code and not Property Builder)
Hmm... Infragistics... I have not used them much but to manually hide a specific column you can use

UltraWebGrid1.Bands(0).Columns.FromKey("YourNameofColKeyHere").Hidden = True

To bind them manually I would presume something along the lines of


but I don't have infragistics with me to check this...
netformxAuthor Commented:
I can check the exact syntex, but I would like to understand the principe. let's assume 1.1 grid:

what should i do in code to set the columns manually (and not to be dependant on sql changes)?

I am binding datagring to datatable like this:
grid.datasource = ...

Is this the wrong thing to do?
does it  cause that all colums in datatable are seen (unless put hidden = true)?
Generally this would cause all columns to be seen.

In a normal DataGrid you can either set the columns up in the design view as stated previously.

or in CodeBehind

BoundColumn myColumn = new BoundColumn();
myColumn.DataField = "MySQLField";
myColumn.HeaderText = "Nice Header";

DataGrid1.AutoGenerateColumns = false;
DataGrid1.DataSource = ds;

So I would setup how ever many columns I need and then whenever my SQL changed as long as the same fields where returned it would work

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.