简体   繁体   English

如何隐藏 DataGridView 中的任何或所有列标题?

[英]How to Hide any or all column header in DataGridView?

I am currently working on a Windows App using C#.我目前正在使用 C# 开发 Windows 应用程序。 I have this datagridview whose first image columns are Edit and Delete.我有这个 datagridview,它的第一个图像列是编辑和删除。 I have an issue with hiding both their headers.我有隐藏他们的标题的问题。 How can I do that, yet keep the headers of the following columns visible?我怎样才能做到这一点,同时保持以下列的标题可见?

Thanks in advance.提前致谢。

While Using C# you can write the following在使用 C# 时,您可以编写以下内容

this.dataGridView1.Columns["CustomerID"].Visible = false;

and to Hide all the column headings you can use:并隐藏您可以使用的所有列标题:

dataGridView1.ColumnHeadersVisible = false;

Select the datagridview and open property, there in property list you can set it to false like mentioned in screenshot .选择 datagridview 并打开属性,在属性列表中,您可以像截图中提到的那样将其设置为 false。

截屏

In your filename.cs file you can add something like this..在您的 filename.cs 文件中,您可以添加这样的内容..

dataGridView1.ColumnHeadersVisible = false;

in your filename.Designer.cs file you will have ..在您的 filename.Designer.cs 文件中,您将拥有 ..

this.dataGridView1.ColumnHeadersVisible = false;

For C# Winforms,对于 C# Winform,

dataGridView1.ColumnHeadersVisible = false;

For asp.net (reader looking for a web solution)对于 asp.net(正在寻找 Web 解决方案的读者)

dataGridView1.ShowHeader = false;

Hide all the column headers隐藏所有列标题

dataGridView.ColumnHeadersVisible = false;

Hide specific column header隐藏特定列标题

dataGridView.Columns[4].Name = "Delete"; //Add name you want
dataGridView.Columns[4].HeaderText = "";

I added a column name and then I put column header text as empty.我添加了一个列名,然后将列标题文本设为空。 But I able to work with column name if it is not visible.但是如果列名不可见,我可以使用它。 This is works for me.这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM