Is there an easy way to do that? Similar to Excel where you can freeze the first column. I have an app that checks on servers and brings back multiple fields. The first field is SERVERNAME and as I scroll horizontally I'd like the 1st column (SERVERNAME) to stay in view as a reference as I scroll past things like RAM, CPU, etc..
Not sure where to begin.
Freeze the 1st column in a grid, Posh Studio 2018
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Freeze the 1st column in a grid, Posh Studio 2018
Where would I do that exactly? I'm doing one of these:
I have an event that sorts the columns Ascending or Descending when clicked. I'm not sure where I would put the column freeze thing. Do you have a code example?
Code: Select all
$DataCollectorSet | Add-Member -Type NoteProperty -Name "SpecMVVFCBM" -Value $SpecMVVFCBM
$DataCollectorSet | Add-Member -Type NoteProperty -Name "OSServername" -Value $CS.Name
#bla bla bla
$DataList += $DataCollectorSet
# Then I stuff the array into the datagrid
$table = ConvertTo-DataTable -InputObject $Datalist #–FilterWMIProperties
Load-DataGridView -DataGridView $datagridviewResults -Item $table
Code: Select all
$datagridviewResults_ColumnHeaderMouseClick = [System.Windows.Forms.DataGridViewCellMouseEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DataGridViewCellMouseEventArgs]
if ($datagridviewResults.DataSource -is [System.Data.DataTable])
{
$column = $datagridviewResults.Columns[$_.ColumnIndex]
$direction = [System.ComponentModel.ListSortDirection]::Ascending
if ($column.HeaderCell.SortGlyphDirection -eq 'Descending')
{
$direction = [System.ComponentModel.ListSortDirection]::Descending
}
$datagridviewResults.Sort($datagridviewResults.Columns[$_.ColumnIndex], $direction)
}
}
Re: Freeze the 1st column in a grid, Posh Studio 2018
Ahh, I see, awesome thanks! I gave it a go and it gave me a duplicate Servername column but it's frozen!
Unfortunately since my code builds the columns on the fly I have to do it programmatically in one of the functions.
Something like:
I just have to translate from the C# examples I've seen and stick it in the right spot.
Unfortunately since my code builds the columns on the fly I have to do it programmatically in one of the functions.
Something like:
Code: Select all
$dataGridView1.Columns[0].Frozen = $true;
$dataGridView1.Columns["Servername"].Frozen = $true;
Re: Freeze the 1st column in a grid, Posh Studio 2018
Got it. I had to reference it as $dataGridViewResults.
Code: Select all
Load-DataGridView -DataGridView $datagridviewclusters -Item $tableClusters
# Putting this AFTER My Load-DataGridView function.
$dataGridViewResults.Columns["Servername"].Frozen = $true;
Re: Freeze the 1st column in a grid, Posh Studio 2018
No. Set the lead column "DataPropertyName" name to the name of the column you want to display and that will be the only one. All other columns will be auto generated.
Attached is a full demo. No changes to the grid other than adding a frozen column in the designer.
Attached is a full demo. No changes to the grid other than adding a frozen column in the designer.
- Attachments
-
- Demo-DGVFrozenColumn.psf
- (19.58 KiB) Downloaded 114 times
Re: Freeze the 1st column in a grid, Posh Studio 2018
It worked but I will check your example out too, thanks!