Hiding default gray column in datagridview winform

C#Winforms

C# Problem Overview


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

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

C# Solutions


Solution 1 - C#

To hide first column you can set RowHeadersVisible to false of your dataGrid

Solution 2 - C#

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

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

Solution 3 - C#

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

Solution 4 - C#

Just put this piece of code. Worked for me.

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

Solution 5 - C#

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-

  1. From (Project's Properties) window change True to false like this:

enter image description here

Solution 6 - C#

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;

Solution 7 - C#

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. I make this in aApp.XAML

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDDRView Question on Stackoverflow
Solution 1 - C#JleruOHePView Answer on Stackoverflow
Solution 2 - C#TomtomView Answer on Stackoverflow
Solution 3 - C#evgenylView Answer on Stackoverflow
Solution 4 - C#Paulo BragaView Answer on Stackoverflow
Solution 5 - C#CrownFordView Answer on Stackoverflow
Solution 6 - C#user6822315View Answer on Stackoverflow
Solution 7 - C#user14642404View Answer on Stackoverflow