hide column in datagrid

how do i hide a column in datagrid.I have used the datagridtablestyle collection however the code does not seem to workcould you help me out with the same please.
thanks,
Supriya
[187 byte] By [Supriya] at [2007-12-16]
# 1

Hi,

Use the, DataViewColumn.Visible property:

dataGridView1.Columns["Col2"].Visible = false;

cheers,

Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
Hi,
I am not using a datagridView control.I am using Datagrid control.So theres no columns collection in Datagrid control.
I tried to use the DatagridTableStyle collection which is not working at all.
could you give me sample code as to how to hide a column in Datagrid control.
Thanks,
Supriya
Supriya at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
The best you can do is set the width of a column to 0.

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

MarkRideout at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4

how to make sure only the columns for the ItemTemplate specified should be displayed in a normal mode and in edit mode more columns should be displayed.

<asp:TemplateField ..>

<ItemTemplate>

...

</ItemTemplate>

<EditItemTemplate>

...

</EditItemTemplate>

</asp:TemplateField>

<asp:TemplateField ..>

<EditItemTemplate>

...

</EditItemTemplate>

</asp:TemplateField>

Both columns will be displayed in both normal and in edit node, even if we don’t specify an ItemTemplate for the other TemplateField. In some cases you probably want to display few columns in normal mode, and some more columns in edit mode. By using the RowDataBound event of the GridView, we can programmatically hide columns. So if we have a GridView with 4 columns (including the edit buttons etc) and want to hide the last two columns, we can do something like this in the RowDataBound event:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (GridView1.EditIndex > 0)

return;

if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) &&

(e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))

{

e.Row.Cells[2].Visible = false;

e.Row.Cells[3].Visible = false;

}

}

Renju.R at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...