This message was discovered on ASPFriends.com 'winforms-cs' list.
| Chris Evans |
I have a DataSet that is returned from a WebService that has five data fields in it. The client is a Windows Form and the code is all in C#. The table that is in the Dataset has these data columns: TaskID, ProjectID, TaskDesc, Hours, Date.
Just binding that to a DataGrid works fine. BUT... I don't want the TaskID and ProjectID columns to be displayed on the DataGrid at all. In ASP.NET I was told I could do something like DataGrid1.Columns[1].Visible = false; I have not verified this will work, but I can't do this in a Windows Work DataGrid. I don't want to removed the two ID columns from the DataSet because one (TaskID) is the primary key, and will be used for other operations, including updating the data, and the other one (ProjectID) will be used for filtering the data.
Any Help??
Chris Click here to reveal e-mail address
|
|
| |
| |
| Paul Smith |
Hi Chris, It is much harder to do this in Windows Form as opposed to a Web Form. However, if you are using Visual Studio .NET you can use the Data Form Wizard ie. right click on the project and select Add New Item, then select the data form wizard, you will be given the option of which columns you want displayed.
----- Original Message ----- From: "Chris Evans" <Click here to reveal e-mail address> To: "winforms-cs" <Click here to reveal e-mail address> Sent: Friday, August 02, 2002 8:56 AM Subject: [winforms-cs] Hiding a Columns in a DataGrid
[Original message clipped]
|
|
| |
|
| |
| Erik Brown |
Chris,
You can also do this in code directly, especially when you have a generic DataSet. Use the TableStyles property of the DataGrid class, which is a DataGridTableStyle collection. These styles in turn contain DataGridColumnStyle collections, which can customize the columns in the grid.
You can probably search for an example online, or this is discussed in detail in chapter 17 of my book.
Erik
======== Erik Brown Author of "Windows Forms Programming with C#" http://www.amazon.com/exec/obidos/ASIN/1930110286
[Original message clipped]
|
|
| |
|
| |
| Per Erik Lorentzen |
This feature is available if you use DataGridColumnStyle. i.e:
DataGridColumnStyle dgcsC1 = new DataGridTextBox(); dgcsC1.Alignment = HorizontalAlignment.Left; dgcsC1.HeaderText = "Task Description"; dgcsC1.Width = 150; dgcsC1.NullText = ""; dgcsC1.MappingName = "TaskDesc";
For each column in the table you want shown, you have to create a DataGridColumnStyle object, from either DataGridTextBox or DataGridBool class.
Then you create DataGridTableStyle(s), and add DataGridColumnStyle objects to its GridColumnStyles collection, i.e:
DataGridTableStyle _gridStyle1 = new DataGridTableStyle(); _gridStyle1.GridColumnStyles.Add(dgcsC1); _gridStyle1.GridColumnStyles.Add(dgcsC2); _gridStyle1.GridColumnStyles.Add(dgcsC3); _gridStyle1.GridColumnStyles.Add(dgcsC4); _gridStyle1.GridColumnStyles.Add(dgcsC5); _gridStyle1.GridColumnStyles.Add(dgcsC6); _gridStyle1.ReadOnly = false; _gridStyle1.AllowSorting = false; _gridStyle1.ForeColor = Color.Black; _gridStyle1.HeaderBackColor = Color.MediumAquamarine; _gridStyle1.HeaderForeColor = Color.Black; _gridStyle1.HeaderFont = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); _gridStyle1.RowHeadersVisible = true; _gridStyle1.RowHeaderWidth = 12; _gridStyle1.GridLineColor = Color.Black; _gridStyle1.MappingName = "TableName";
The MappingName is the name of the table in the DataSet object. You can have several tables in a DataSet object, so naturally you must create DataGridTableStyle objects for each table.
Finally you add the DataGridTableStyle(s) to the TableStyles collection of the DataSet, i.e:
this.dataGrid1.DataSource = myDataSet; this.dataGrid1.DataMember = "TableName"; this.dataGrid1.TableStyles.Add(_gridStyle1);
And that should be it...
Med hilsen Per Erik Lorentzen SK Data as Click here to reveal e-mail address ----- Original Message ----- From: "Chris Evans" <Click here to reveal e-mail address> To: "winforms-cs" <Click here to reveal e-mail address> Sent: Friday, August 02, 2002 12:56 AM Subject: [winforms-cs] Hiding a Columns in a DataGrid
[Original message clipped]
|
|
| |
|
|
|
|
|