Hide the first Column

Is it possible to hide the first Column in a DataGrid Let me explain a few things first.

The DataSource for the DataGrid is like so;

DataSet DSAccountVenueRooms = new DataSet();

DSAccountVenueRooms = DataAccess.GetAccountVenueRooms(MainMenu.AccountID);

this.dgAccountVenueRoom.DataSource = DSAccountVenueRooms.Tables[0];

The first Column in this DataGrid is a RoomID Value that I get to execute the next Stored Procedure to get the Data for that Room. So I need the first Column called RoomID but I do not need to show the user this Column as it means nothing to them!

Can this be done



Answer this question

Hide the first Column

  • EJP001

    You can set the first column's Width to 0.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • Younis

    The problem is that I need to get the value of the first column in the cell that a user clicks on as I use it to pass that value (ContactID) to a stored procedure. The reason I need to hide it is that it means nothing to the user. Its only used for the stored procedure.
  • Brian Ceccarelli

    BonnieB,

    Could you please post your code again as it didn't make it onto this thread.

  • Gka

    You're welcome!! (assuming it does what you need it to do ... Big Smile )

  • Raghuraman_ace

    You need to mess around with the DataGrid's TableStyles and ColumnStyles. It's a lot of work, but the only way I know of to do this. =(

    Maybe it's easier with VS 2005, but I haven't used it, so I don't know.

  • JamesGreene

    I didn't post any code the first time, but here's a real quick-and-dirty ... I'd make it a little nicer to read if I were you, but this gets the idea across:

    this.oGrid.DataSource = null;

    this.oGrid.TableStyles.Clear();

    this.oGrid.TableStyles.Add(new DataGridTableStyle());

    this.oGrid.TableStyles[0].MappingName = this.MyDataSet.Tables[0].TableName;

    this.oGrid.TableStyles[0].GridColumnStyles.Add(new DataGridTextBoxColumn());

    this.oGrid.TableStyles[0].GridColumnStyles[0].MappingName = "Description";

    this.oGrid.TableStyles[0].GridColumnStyles.Add(new DataGridTextBoxColumn());

    this.oGrid.TableStyles[0].GridColumnStyles[1].MappingName = "SortOrder";

    this.oGrid.SetDataBinding(this.oDataFromXML, this.MyDataSet.Tables[0].TableName);



  • achopp

    Mark,

    I have had a look at the dataGrid properties and I can't seem to get to the Columns of a dataGrid to set the first column to a width of 0.

    Can you show how

  • Perter

    Thanks Bonnie. I'll give it a go.
  • Hide the first Column