473,803 Members | 3,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Make some columns invisible in DataGrid dynamically

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
Nov 19 '05 #1
4 4092
You should be able to access each column's visible property like so:

dgDataGrid.Colu mns(3).visible = false

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com

"david" <da***@discussi ons.microsoft.c om> wrote in message
news:1A******** *************** ***********@mic rosoft.com...
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

Nov 19 '05 #2
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
"david" <da***@discussi ons.microsoft.c om> wrote in message
news:1A******** *************** ***********@mic rosoft.com...
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

Nov 19 '05 #3
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

"S. Justin Gengo" wrote:
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
"david" <da***@discussi ons.microsoft.c om> wrote in message
news:1A******** *************** ***********@mic rosoft.com...
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


Nov 19 '05 #4
Hi, David Lozzi:

dgDataGrid.Colu mns(3).visible = false

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

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

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

dgDataGrid.Colu mns(3).visible = false

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com

"david" <da***@discussi ons.microsoft.c om> wrote in message
news:1A******** *************** ***********@mic rosoft.com...
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


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1883
by: Igor Mendizabal | last post by:
Hello, We're doing our own datagrid based on the System.windows.forms.datagrid control, and are having some problems with horizontal scrolling. In general, we construct our datagrid adding a tablestyle and gridcolumnstyles to that tablestyle. If we have invisible columns, we add the gridcolumnstyle with Width = 0 (couldn't find any other way to do it, because there is no Visible property available...).
3
2550
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would look like this :
0
2274
by: Bob | last post by:
I have a data grid with a template column. Sometimes I need this column to be read-only, even in edit mode. Does anyone know how to do this. I get the other columns by running through the DataGrid.Columns and testing for column type. Then I can set ReadOnly for Bound columns or make the Edit or PushButton columns invisible, but I can't seem to do this with a template column. Is there any way to access the control used in EditItemTemplate...
6
2436
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a DataGrid in a web user control (.ascx) I am creating. This applies to VS.NET 2003 / Framework 1.1.
8
7321
by: Hanson | last post by:
I have a datagrid control in an aspx page. The datagrid columns will be dynamically generated according to the pre-page's search condition, I want to hide some columns in the datagrid. is that anyway to do that?
3
2163
by: Richard | last post by:
After printing a userlist to a Datagrid i want some names not to be shown. I want to know how i can make a entire datagrid row invisible. I suspect its something with the OnItemDatabound but i am kinda stuck there. but this is basicly what i want. if Username = "Deleted_User" then 'make entire table row invisible. End if
2
1739
by: Michael Chong | last post by:
Hi, How can I make a column in Datagrid invisible programmatically during run-time? I did try the following but doesn't work. DataGridLedger.DataSource = myDataSet DataGridLedger.DataMember = "ParentTable" DataGridLedger.DataBind() DataGridLedger.Visible = True DataGridLedger.Columns(1).Visible = False
15
3767
by: John Blair | last post by:
Hi, Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks. MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors",
3
1849
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: 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. The following Possible solution do not work:
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.