|
-
Nov 6th, 2007, 11:33 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Hide columns in Datagrid
Hello,
VS 2005 WM 6.0
I am using the following code to hide the grid columns. As I have a lot of grid columns to hide, it is showing a thick bold line where the grid column would be. I wanted to make the columns totally invisble by setting the width to 0. However, I am wondering if there is a better method as the customer doesn't like having the thick bold line, as you can see there are some there.
Here is my code for hiding, is there something better.
Code:
//GridTableStylesCollection grdTblSty = new GridTableStylesCollection();
DataGridTableStyle tblStyle = new DataGridTableStyle();
tblStyle.MappingName = "OrderDetail";
grdBeverages.TableStyles.Add(tblStyle);
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["OrderDetailID"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["BeverageID"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["Beverage"].Width = 50;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["BeverageQty"].Width = 40;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["BeverageQty"].HeaderText = "Qty";
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["BeverageCost"].Width = 40;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["BeverageCost"].HeaderText = "Cost";
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["StarterID"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["Starter"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["StarterQty"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["StarterCost"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["MaincourseID"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["Maincourse"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["MaincourseQty"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["MaincourseCost"].Width = 0;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["TotalCost"].Width = 40;
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["totalCost"].HeaderText = "Cost";
grdBeverages.TableStyles["OrderDetail"].GridColumnStyles["OrderID"].Width = 0;
Many thanks for any advice,
Steve
-
Nov 6th, 2007, 11:41 PM
#2
Junior Member
Re: Hide columns in Datagrid
Filter the query results of your data table to exclude columns who are not IDs.
VB.Net Version : 2005
.Net Version : 2.0
OS : Windows XP SP2
-------------------------
 ALways be COOL 
-
Nov 10th, 2007, 01:16 PM
#3
Thread Starter
Frenzied Member
Re: Hide columns in Datagrid
Hello,
Thanks for your suggestion, but that wouldn't work. I need all the columns but don't want to display some.
I am still looking for a suitable solution to this problem.
Many thanks for any more suggestions on this problem.
Steve
-
Nov 11th, 2007, 03:38 AM
#4
Frenzied Member
Re: Hide columns in Datagrid
Hi,
try setting the column width of the columns you don't want to see, to zero
Pete
-
Nov 11th, 2007, 03:41 AM
#5
Thread Starter
Frenzied Member
Re: Hide columns in Datagrid
Hello Pete.
Thanks for your reply, yes that is what I did in my first post.
However, there was a black bold line where the column should be. The customer didn't like to see this. As you can see there are many columns I need to hide.
Thanks for any more suggestions,
Steve
-
Nov 11th, 2007, 05:29 AM
#6
Frenzied Member
Re: Hide columns in Datagrid
Hi,
sorry - didn't read it properly. What about if you put all the columns you didn't want to see at the far right.
Do you use a dataset to populate your grid - if so, you could try
dsGeneral.Tables("General").Columns("Product_Name").ColumnMapping = MappingType.Hidden, and this has another possibility
Pete
-
Nov 11th, 2007, 07:58 AM
#7
Thread Starter
Frenzied Member
Re: Hide columns in Datagrid
Hello Pete,
Thanks for your continued support.
This didn't work.
dsGeneral.Tables("General").Columns("Product_Name").ColumnMapping = MappingType.Hidden
I need to test the other website, but it doesn't look too promising.
Thanks if you have any other ideas.
Steve
-
Nov 12th, 2007, 09:12 AM
#8
Thread Starter
Frenzied Member
Re: Hide columns in Datagrid
Hello,
I have found some code that seems to work. However, the idea of the grid is for the user to keep adding new products to the datagrid. Even though the columns that are needed are added ok. When the user attempts to add a second row there is an error. ""Value does not fall within the expected range". This happens each time, after the first one has been successfully added. 2nd one onwards.
I thought it might be the tblStyle object, but as I am creating a new one each time, I am surprised to get this error.
vb Code:
DataGridTableStyle tblStyle = new DataGridTableStyle();
tblStyle.MappingName = "OrderDetail";
DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.MappingName = "Beverage";
column.HeaderText = "Beverage";
tblStyle.GridColumnStyles.Add(column);
column = new DataGridTextBoxColumn();
column.MappingName = "BeverageQty";
column.HeaderText = "Quantity";
tblStyle.GridColumnStyles.Add(column);
grdBeverages.TableStyles.Add(tblStyle); //Error - "Value does not fall within the expected range"
grdBeverages.DataSource = DS.OrderDetail.DefaultView;
Many thanks if you have any ideas about this,
Steve
-
Nov 15th, 2007, 05:32 AM
#9
Thread Starter
Frenzied Member
Re: Hide columns in Datagrid
Problem solved,
You cannot have a second table style.
vb Code:
grdBeverages.TableStyles.Clear()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|