473,583 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide datagrid column

Das
Hi everyone,
I'm using datagrid control to display the data. I want to hide column to be
displayed into the data grid. I'm using the code as given below:

Method given below is used to bind the data grid with the db:

public static void DataGrid(DataGr id DG,string sql)
{

//Initialize connection with the db
SqlConnection co =initConnection ();

SqlDataAdapter myCommand = new SqlDataAdapter( sql, co );
DataSet ds = new DataSet();
myCommand.Fill( ds);

DG.DataSource =ds.Tables[0].DefaultView;

co.Close();
}

clsGeneral.Data Grid(dgDestinat ion,"Select strCode as Code, strName as Name,
acDestination from tblDestination where acDestination != 0");

// Set the DataGridTableSt yle.MappingName property
// to the table in the data source to map to.
ts.MappingName = "tblDestination ";
// Add it to the datagrid's TableStyles collection

// Create new DataGridColumnS tyle objects.
DataGridColumnS tyle acDestination = new DataGridTextBox Column();
acDestination.M appingName = "acDestination" ;
//cOrderDate.Head erText = "Order Date";
acDestination.W idth = 0;
ts.GridColumnSt yles.Add(acDest ination);
dgDestination.T ableStyles.Add( ts);
dgDestination.R efresh();

I'm using the code as given in link below. I don't know what's wrong with
the code

http://msdn.microsoft.com/library/de...ingcolumns.asp
Thanks in advance...

Regards,

das

Nov 17 '05 #1
6 8404
Hi Das,

Just don't add a DataGridColumnS tyle for the column you want to hide to the
GridColumnStyle s collection .

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Das" <Da*@discussion s.microsoft.com > wrote in message
news:A6******** *************** ***********@mic rosoft.com...
Hi everyone,
I'm using datagrid control to display the data. I want to hide column to
be
displayed into the data grid. I'm using the code as given below:

Method given below is used to bind the data grid with the db:

public static void DataGrid(DataGr id DG,string sql)
{

//Initialize connection with the db
SqlConnection co =initConnection ();

SqlDataAdapter myCommand = new SqlDataAdapter( sql, co );
DataSet ds = new DataSet();
myCommand.Fill( ds);

DG.DataSource =ds.Tables[0].DefaultView;

co.Close();
}

clsGeneral.Data Grid(dgDestinat ion,"Select strCode as Code, strName as
Name,
acDestination from tblDestination where acDestination != 0");

// Set the DataGridTableSt yle.MappingName property
// to the table in the data source to map to.
ts.MappingName = "tblDestination ";
// Add it to the datagrid's TableStyles collection

// Create new DataGridColumnS tyle objects.
DataGridColumnS tyle acDestination = new DataGridTextBox Column();
acDestination.M appingName = "acDestination" ;
//cOrderDate.Head erText = "Order Date";
acDestination.W idth = 0;
ts.GridColumnSt yles.Add(acDest ination);
dgDestination.T ableStyles.Add( ts);
dgDestination.R efresh();

I'm using the code as given in link below. I don't know what's wrong with
the code

http://msdn.microsoft.com/library/de...ingcolumns.asp
Thanks in advance...

Regards,

das


Nov 17 '05 #2
Das
Hi there,
thanks for the reply,

I have done that as well. I added the DataGridColumnS tyle for all other
column. I mean what I did that I added the DataGridColumnS tyle for other
columns as given below:

DataGridColumnS tyle strCode = new DataGridTextBox Column();
strCode.Mapping Name = "strCode";
ts.GridColumnSt yles.Add(strCod e);
DataGridColumnS tyle strName = new DataGridTextBox Column();
strName.Mapping Name = "strName";
ts.GridColumnSt yles.Add(strNam e);

dgDestination.T ableStyles.Add( ts);
dgDestination.R efresh();

I'm defining the mappingName with the field I think this is the way you want
me to set the column style for the rest of the columns. But it doean't seems
working. I don't know what's wrong with code.

But there should be some other way because I only want to hide one column.
I simply want to width of only one column. Rest should be ok.

Regards,

das

"Dmytro Lapshyn [MVP]" wrote:
Hi Das,

Just don't add a DataGridColumnS tyle for the column you want to hide to the
GridColumnStyle s collection .

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Das" <Da*@discussion s.microsoft.com > wrote in message
news:A6******** *************** ***********@mic rosoft.com...
Hi everyone,
I'm using datagrid control to display the data. I want to hide column to
be
displayed into the data grid. I'm using the code as given below:

Method given below is used to bind the data grid with the db:

public static void DataGrid(DataGr id DG,string sql)
{

//Initialize connection with the db
SqlConnection co =initConnection ();

SqlDataAdapter myCommand = new SqlDataAdapter( sql, co );
DataSet ds = new DataSet();
myCommand.Fill( ds);

DG.DataSource =ds.Tables[0].DefaultView;

co.Close();
}

clsGeneral.Data Grid(dgDestinat ion,"Select strCode as Code, strName as
Name,
acDestination from tblDestination where acDestination != 0");

// Set the DataGridTableSt yle.MappingName property
// to the table in the data source to map to.
ts.MappingName = "tblDestination ";
// Add it to the datagrid's TableStyles collection

// Create new DataGridColumnS tyle objects.
DataGridColumnS tyle acDestination = new DataGridTextBox Column();
acDestination.M appingName = "acDestination" ;
//cOrderDate.Head erText = "Order Date";
acDestination.W idth = 0;
ts.GridColumnSt yles.Add(acDest ination);
dgDestination.T ableStyles.Add( ts);
dgDestination.R efresh();

I'm using the code as given in link below. I don't know what's wrong with
the code

http://msdn.microsoft.com/library/de...ingcolumns.asp
Thanks in advance...

Regards,

das


Nov 17 '05 #3
Das,

What exactly happens? The Column which you try to hide is still
present? Here I made some tests and I was successfuly able to hide the
column, also instead of "width" it to 0 try to set the MapingName to
empty string. Here the both methods works.

Regards,

Philip.

Nov 17 '05 #4
Das,

Why do not try to "zero width" the desired column after adding it to
the DataGridColumnS tyle collection? Something like this:
DataGrid1.Table Styles(0).GridC olumnStyles(0). Width = 0

It should work!

@Dmytro
I believe he wants to hide the column, not just not to show it. When
given column is hidden, it can be easily shown later, without creating
new one and adding it to collection.

Best wishes to both of you,

Philip.

Nov 17 '05 #5
Das,

Make sure you define the table and column styles BEFORE you bind the grid to
the data source. Also, I'd recommend that you use the SetDataBinding method
to specify the data source and the data member (as opposed to setting the
corresponding properties directly).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Das" <Da*@discussion s.microsoft.com > wrote in message
news:22******** *************** ***********@mic rosoft.com...
Hi there,
thanks for the reply,

I have done that as well. I added the DataGridColumnS tyle for all other
column. I mean what I did that I added the DataGridColumnS tyle for other
columns as given below:

DataGridColumnS tyle strCode = new DataGridTextBox Column();
strCode.Mapping Name = "strCode";
ts.GridColumnSt yles.Add(strCod e);
DataGridColumnS tyle strName = new DataGridTextBox Column();
strName.Mapping Name = "strName";
ts.GridColumnSt yles.Add(strNam e);

dgDestination.T ableStyles.Add( ts);
dgDestination.R efresh();

I'm defining the mappingName with the field I think this is the way you
want
me to set the column style for the rest of the columns. But it doean't
seems
working. I don't know what's wrong with code.

But there should be some other way because I only want to hide one column.
I simply want to width of only one column. Rest should be ok.

Regards,

das

"Dmytro Lapshyn [MVP]" wrote:
Hi Das,

Just don't add a DataGridColumnS tyle for the column you want to hide to
the
GridColumnStyle s collection .

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Das" <Da*@discussion s.microsoft.com > wrote in message
news:A6******** *************** ***********@mic rosoft.com...
> Hi everyone,
> I'm using datagrid control to display the data. I want to hide column
> to
> be
> displayed into the data grid. I'm using the code as given below:
>
> Method given below is used to bind the data grid with the db:
>
> public static void DataGrid(DataGr id DG,string sql)
> {
>
> //Initialize connection with the db
> SqlConnection co =initConnection ();
>
> SqlDataAdapter myCommand = new SqlDataAdapter( sql, co );
> DataSet ds = new DataSet();
> myCommand.Fill( ds);
>
> DG.DataSource =ds.Tables[0].DefaultView;
>
> co.Close();
> }
>
>
>
> clsGeneral.Data Grid(dgDestinat ion,"Select strCode as Code, strName as
> Name,
> acDestination from tblDestination where acDestination != 0");
>
> // Set the DataGridTableSt yle.MappingName property
> // to the table in the data source to map to.
> ts.MappingName = "tblDestination ";
>
>
> // Add it to the datagrid's TableStyles collection
>
> // Create new DataGridColumnS tyle objects.
> DataGridColumnS tyle acDestination = new DataGridTextBox Column();
> acDestination.M appingName = "acDestination" ;
> //cOrderDate.Head erText = "Order Date";
> acDestination.W idth = 0;
> ts.GridColumnSt yles.Add(acDest ination);
> dgDestination.T ableStyles.Add( ts);
> dgDestination.R efresh();
>
> I'm using the code as given in link below. I don't know what's wrong
> with
> the code
>
> http://msdn.microsoft.com/library/de...ingcolumns.asp
>
>
> Thanks in advance...
>
> Regards,
>
> das
>



Nov 17 '05 #6
Das
hi everyone,
The way I'm setting the datasource. It by default assings the MappingName
as "Table". Not the originational database table because I was assigning the
database query result to the datasource.

What I did that I defined the mapping name from table stlyes as "Table"
then it started working.

Thanks everybody for your support.

Regards,

das

"Philip Hristov" wrote:
Das,

What exactly happens? The Column which you try to hide is still
present? Here I made some tests and I was successfuly able to hide the
column, also instead of "width" it to 0 try to set the MapingName to
empty string. Here the both methods works.

Regards,

Philip.

Nov 17 '05 #7

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

Similar topics

6
6276
by: CBuck | last post by:
Hi, I was wondering if it was possible to hide the first column of the datagrid (windows form control). The column that I am referring to is the column created by the control that is gray in color and contains the selection arrow. My goal is to use the datagrid in place of a ListView control for performance reasons. To keep this new control...
2
4301
by: Thanh Nu | last post by:
Hi, I would like to hide a column in a web datagrid (with create columns automatically at runtime checked), and I cannot refer to the columns collection like this: DataGrid1.Columns(0).Visible = False (the message at runtime is something like index out of range, and under the debuger, I discover that the attribute count of the columns...
1
2725
by: enak | last post by:
I populate a datagrid by setting the datasource to a datatable. I then, bind them. After that I try to hide the last column but am not able to. I get an error message. Here is my code: Me.dgReport.DataSource = ds.Tables("tFirst") Me.dgReport.DataBind() Me.dgReport.Columns(7).Visible = False
8
7307
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
1708
by: sivaraman.S | last post by:
Hi friends, How to hide a column in datagrid. regards, Sivaraman.S
5
7805
by: J | last post by:
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid? -- Jason
2
18880
by: Keithb | last post by:
I need to hide a GridView's "edit" column if the user's role does not support editing. However, the column's Visible property does not support databinding. Is there a workaround? Thanks, Keith
1
2995
by: nuhura01 | last post by:
Hi all.. I have a datagrid in my system and I preview the datagrid in other html page. Below are the code that I'm using: Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
1
2285
by: TonyJ | last post by:
Hello! Assume I have a datasource consisting of a database table. This table has 5 column. If I now want to use a bound datagrid but want to display only 4 of these 5 columns is that possible. How is that done?
0
7888
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...
0
7811
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...
0
8159
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. ...
0
8314
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...
1
7922
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6571
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...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1416
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.