C# 在 datagridview winform 中隐藏默认灰色列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15653306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 17:28:56  来源:igfitidea点击:

Hiding default gray column in datagridview winform

c#winforms

提问by DDR

Is there any way to remove or hide winform's datagrid gray area when data is not avaiable?

当数据不可用时,有没有办法删除或隐藏winform的数据网格灰色区域?

Second this how to remove/hide the default gray column?

其次这个如何删除/隐藏默认的灰色列?

  dataGridView1.DataSource = oresult;
  dataGridView1.Columns["Id"].Visible  = false;
  dataGridView1.Columns["AddedBy"].Visible = false;
  dataGridView1.Columns["AddmissionInClass"].Visible = false;
  dataGridView1.Columns["IsDeleted"].Visible = false;
  dataGridView1.Enabled = false;

I'm hiding useless columns like this but unable to find way to hide these.

我隐藏了这样无用的列,但无法找到隐藏这些的方法。

enter image description here

在此处输入图片说明

采纳答案by JleruOHeP

To hide first column you can set RowHeadersVisibleto false of your dataGrid

要隐藏第一列,您可以将RowHeadersVisibledataGrid设置为 false

回答by Tomtom

Just set the Background-Color and the RowHeadersVisible-State of your DataGridView:

只需设置 DataGridView 的 Background-Color 和 RowHeadersVisible-State:

dataGridView1.BackgroundColor = Color.White;
dataGridView1.RowHeadersVisible = false;

回答by evgenyl

You need set properties for RowHeaderVisible (from gridview properties) to be false

您需要将 RowHeaderVisible 的属性(来自 gridview 属性)设置为 false

回答by user6822315

If you are trying to delete grid view column in column level and its not being reflected in grid view please follow as below: We can't delete the column of grid view in column level. So, delete the column's cell in row level (means in each and every row).

如果您尝试删除列级别的网格视图列并且它没有反映在网格视图中,请按照以下操作: 我们无法删除列级别的网格视图列。因此,删除行级别的列单元格(意味着在每一行中)。

foreach (GridViewRow Row in this.searchResults.SearchResultGrid.Rows)
                    {
                        if (Row.RowType == DataControlRowType.DataRow)
                        {
                            Row.Cells[0].Visible = false;
                        }
                    }
                    GridViewRow HeaderRow = this.searchResults.SearchResultGrid.HeaderRow;
                    HeaderRow.Cells[0].Visible = false;

回答by Paulo Braga

Just put this piece of code. Worked for me.

把这段代码放上就行了。为我工作。

DataGrid.RowHeadersVisible = false;
DataGrid.ColumnHeadersVisible = false;

回答by CrownFord

You have two approaches to do this:

您有两种方法可以做到这一点:

  1. Adding this line:

    dataGridView1.RowHeadersVisible = false;
    

    to...

    private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.RowHeadersVisible = false;
    }
    

    -OR-

  2. From (Project's Properties) window change Trueto falselike this:

  1. 添加这一行:

    dataGridView1.RowHeadersVisible = false;
    

    到...

    private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.RowHeadersVisible = false;
    }
    

    -或者-

  2. 从(项目的属性)窗口将True更改为false,如下所示:

enter image description here

在此处输入图片说明