Showing posts with label Datagridview. Show all posts
Showing posts with label Datagridview. Show all posts

2016/07/28

PowerShell/WinForms - Row Header

If you are creating Windows Forms (WinForms) using PowerShell with tools such as PowerShell Studio from Sapien, you might have some scenario where you want to use Row Header instead of Column Header in a DataGridView control.

Those can be controlled using the properties RowHeaderVisible and ColumnHeaderVisible.




Assuming you already have a form with a Datagridview in it, you will need to do the following:
  • Create a Column
  • Create a Row with the Header value (and optionally a value for the first column)
  • Add the Row to the DataGridView
  • Set RowHeaderVisible to $true
  • Set ColumnHeaderVisiable to $false (Optional)
(The example can be download on my github)


Creating a Column

# Create Column object
$NewColumn = New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn
$NewColumn.Name = "Column1"
$NewColumn.HeaderText = "Column1"

# Add the Column to the Datagridview
$DataGridView.Columns.Add($NewColumn)

2015/01/10

PowerShell Studio 2014 - DataGridView Sorting

When creating graphical tools with PowerShell Studio 2014 and using the DataGridView control, I often find myself looking for the following tip!

The DataGridView control provides a customizable table for displaying data. You can extend the DataGridView control in a number of ways to build custom behaviors into your applications. A DataView provides a means to filter and sort data within a DataTable. The following example shows how to sort a DataGridView by using a DataTable Object.

In this example, I'm using PowerShell Studio 2014 from SAPIEN, you can download a 45 days trial version here.