locked
Hide DataView Row Headers RRS feed

  • Question

  • Is there a way to hide the row headers of a dataview?

    $Form = New-Object System.Windows.Forms.Form
    $Form.Size = New-Object System.Drawing.Size(600,400)
    $DataGridView = New-Object System.Windows.Forms.DataGridView
    $DataGridView.Location =  New-Object System.Drawing.Point(5,25)
    $DataGridView.Size = New-Object System.Drawing.Size(565,410)
    $DataGridView.ColumnHeadersHeight = 30
    $DataGridView.RowHeadersWidth = 1
    $col1 = New-Object System.Windows.Forms.DataGridViewTextboxColumn
    $col1.Name = 'Col1'
    $col1.Width = 50
    $DataGridView.Columns.Add($col1)
    $col2 = New-Object System.Windows.Forms.DataGridViewTextboxColumn
    $col2.Name = 'Col2'
    $col2.Width = 50
    $DataGridView.Columns.Add($col2)
    $Form.Controls.Add($DataGridView)
    $Form.ShowDialog()

    Saturday, December 29, 2018 10:12 PM

Answers

All replies

    • Marked as answer by Ian3 Saturday, December 29, 2018 11:39 PM
    Saturday, December 29, 2018 10:54 PM
  • I mean that I do not want the row headers show up so I try to use $DataGridView.RowHeadersWidth = 1

    but the row headers on the left side of DataGridView is still there. If I set it to 0, I got error.

    Saturday, December 29, 2018 11:04 PM
  • The link I posted tells you exactly how to hide all headers; row and column.


    \_(ツ)_/

    Saturday, December 29, 2018 11:32 PM
  • You can also find all f the properties that control the grid here: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview?view=netframework-4.7.2

    When trying to use any control in forms it is always best to start with the documentation.


    \_(ツ)_/


    • Marked as answer by Ian3 Saturday, December 29, 2018 11:40 PM
    • Edited by jrv Saturday, December 29, 2018 11:41 PM
    Saturday, December 29, 2018 11:34 PM
  • Thanks a lot.
    Saturday, December 29, 2018 11:40 PM
  • Here is the better way to build a form. You MUST add the assembly if it is going to run from a PS1 file.

    Add-Type -AssemblyName System.Windows.Forms
    
    $form = New-Object System.Windows.Forms.Form
    $form.Size = '600, 400'
    $form.StartPosition = 'CenterScreen'
    
    $dataGridView = New-Object System.Windows.Forms.DataGridView
    $form.Controls.Add($dataGridView)
    $dataGridView.Location = '5, 25'
    $dataGridView.Size = '565, 410'
    $dataGridView.RowHeadersVisible = $false
    
    $col1 = New-Object System.Windows.Forms.DataGridViewTextboxColumn
    $dataGridView.Columns.Add($col1)
    $col1.Name = 'Col1'
    $col1.Width = 50
    
    $col2 = New-Object System.Windows.Forms.DataGridViewTextboxColumn
    $dataGridView.Columns.Add($col2)
    $col2.Name = 'Col2'
    $col2.Width = 50
    
    $form.ShowDialog()

    A DGV can autoload objects and auto-generate columns so it is not always necessary to create them.


    \_(ツ)_/



    • Edited by jrv Saturday, December 29, 2018 11:44 PM
    Saturday, December 29, 2018 11:42 PM
  • # example of auto generate grid
    Add-Type -AssemblyName System.Windows.Forms $form = New-Object System.Windows.Forms.Form $form.Size = '600, 400' $form.StartPosition = 'CenterScreen' $dataGridView = New-Object System.Windows.Forms.DataGridView $form.Controls.Add($dataGridView) $dataGridView.Dock = 'Fill' $dataGridView.RowHeadersVisible = $false [System.Collections.ArrayList]$files = Get-ChildItem -file | Select Name, Length, CreationTime $dataGridView.DataSource = $files $form.ShowDialog()


    \_(ツ)_/



    • Edited by jrv Saturday, December 29, 2018 11:49 PM
    Saturday, December 29, 2018 11:47 PM