简体   繁体   English

在datagridview winform中隐藏默认的灰色列

[英]Hiding default gray column in datagridview winform

Is there any way to remove or hide winform's datagrid gray area when data is not avaiable?当数据不可用时,有什么方法可以删除或隐藏 winform 的 datagrid 灰色区域?

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.我正在隐藏这样的无用列,但无法找到隐藏这些的方法。

在此处输入图像描述

要隐藏第一列,您可以将数据网格的RowHeadersVisible设置为 false

Just set the Background-Color and the RowHeadersVisible-State of your DataGridView:只需设置 DataGridView 的 Background-Color 和 RowHeadersVisible-State:

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

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

Just put this piece of code.放上这段代码就行了。 Worked for me.为我工作。

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

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 True to false like this:从(项目的属性)窗口将True更改为false ,如下所示:

在此处输入图像描述

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;
DGV.RowHeadersDefaultCellStyle.Padding = New Padding(3)

Although a few years have passed but I have reached it now... I had to change it in all the DataGrids in all the project.虽然几年过去了,但我现在已经达到了......我不得不在所有项目的所有 DataGrids 中更改它。 I make this in aApp.XAML我在 aApp.XAML 中做这个

  <Style TargetType="DataGrid">
 <Setter Property="RowHeaderWidth" Value="0"/>
   </Style>

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

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