Make some columns invisible in DataGrid dynamically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have datasource, say, ds which is bounded to a datagrid, dg.
Assume that ds have 5 columns, c0,c1,c2,c3,c4.
In some case, say, case 1, I want to display columns c0, c1,c2 in dg and use
c3 and c4 in code behind.
In case 2, I want to display column c0, c3, and c4, and use c1 and c2 in
code behind.

Anyone can tell how to do it?

Thanks

David
 
You should be able to access each column's visible property like so:

dgDataGrid.Columns(3).visible = false
 
David,

Use the datagrid's OnItemDatabound event.

I have some code on my website for adding a checkbox to a datagrid
dynamically that would be a way for you to become familiar with the
OnItemDatabound event. If you'd like to take a look at it you may find it by
using the search box on this page:
http://www.aboutfortunate.com?page=codelibrary to search for "Checkbox in
Datagrid"

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Thank you, David Lozzi and Justin Gengo:
I will try it.
I would be interested in OnItemDatabound event as well, since I did someting
in part which is related to this topic.

David
 
Hi, David Lozzi:

dgDataGrid.Columns(3).visible = false

is only working for the selected columns in DataGrid Property Builder in
design.

I have tried dgDataGrid.Itemss(3).visible = false. But it does not work.
 

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

Back
Top