Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding columns in a datagrid

Status
Not open for further replies.

robert201

Programmer
Jul 18, 2007
80
TH
Hello

VS 2003.

I am trying to hide some columns in a datagrid. The datagrid is bound to a typed dataset data source.

This is the code I have used to set the column width to zero. However, as there are many columns to hide I get left with a bold black line where the column should have been. So the customer doesn't want to see this. This is the code I used, just wondering is there a better way to do this.

Many thanks,

Steve


Code:
//GridTableStylesCollection grdTblSty = new GridTableStylesCollection();
                DataGridTableStyle tblStyle = new DataGridTableStyle();
                tblStyle.MappingName = "OrderDetail";
                grdBeverages.TableStyles.Add(tblStyle);

                grdBeverages.DataSource = DS.OrderDetail.DefaultView;
                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;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top