Looking for assistance on how to create/code the datagridview columns design Column Type. I know how to manually set it in the Misc/Columns/(Collection) area within Sapien PowerShell Studio. I am thinking i have to reference my datagridview/column to column type [System.Windows.Forms.DataGridViewImageColumn] but i don't know how that is set or property it is on. Tried searching the forums, don't see an article of creating datagridview from scratch/coded. The reason why i am creating from scratch is i clear the datagridview/datasource. Thanks,
Currently Setting Example:
$datagridview3.Columns[0].Width = '110'
$datagridview3.Columns[1].Width = '110'
$datagridview3.Columns[2].Width = '110'
$datagridview3.Columns[2].DefaultCellStyle.Alignment = 'middlecenter'
Datagridview - DataGridViewImageColumn
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.
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: Datagridview - DataGridViewImageColumn
Clearing the data source does not clear the formatting. Set the column auto size mode to automatically set the column width.
If you clear the data source and have no pre-defined columns then the columns WILL be cleared. A new data source will recreate the columns.
There is really not enough information to understand your issue. How you load the data is critical to the behavior of the columns collection.
If you clear the data source and have no pre-defined columns then the columns WILL be cleared. A new data source will recreate the columns.
There is really not enough information to understand your issue. How you load the data is critical to the behavior of the columns collection.
Re: Datagridview - DataGridViewImageColumn
The following creates a column and sets some properties.
Code: Select all
Add-Type -AssemblyName System.Windows.Forms
$dgv = New-Object System.Windows.Forms.DataGridView
$dgv.Columns.Add('MyColumn', 'MyHeader')
$dgv.Columns['MyColumn'].Width = 100
$dgv.Columns['MyColumn'].DefaultCellStyle.Alignment = 'middlecenter'
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: Datagridview - DataGridViewImageColumn
Np, will explain a bit more....
I have the formatting set in the Misc/Columns/(Collection), created table names. I have a tabcontrol when clicked loads the below routine. It works the first time with no issues in regards to the formatting. If I click another tab and come back to that tab it loads the datagridview with the data but does not keep the formatting. Note this routine is being done as part of add-jobtracker in the completedscript part. If i take out the clearing datasource it is fine. Do you think i really need to clear the datasource?
I have the formatting set in the Misc/Columns/(Collection), created table names. I have a tabcontrol when clicked loads the below routine. It works the first time with no issues in regards to the formatting. If I click another tab and come back to that tab it loads the datagridview with the data but does not keep the formatting. Note this routine is being done as part of add-jobtracker in the completedscript part. If i take out the clearing datasource it is fine. Do you think i really need to clear the datasource?
Code: Select all
$datagridview3.DataSource = $null
$list2 = [system.collections.arraylist]($results.'Tabview' | select 'Name', 'Icon', 'State', 'IP Address', 'Traffic Domain')
$datagridview3.DataSource = $list2
foreach ($Row in $datagridview3.Rows)
{
if ($Row.Cells[2].Value -eq 'ENABLED') { $Row.Cells[1].Value = $IconSuccess }
if ($Row.Cells[2].Value -eq 'DISABLED') { $Row.Cells[1].Value = $IconError }
}
Re: Datagridview - DataGridViewImageColumn
Why do you keep reloading the data?
Start by removing this line: "$datagridview3.DataSource = $null" as it is unnecessary and will remove all formatting.
Start by removing this line: "$datagridview3.DataSource = $null" as it is unnecessary and will remove all formatting.
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: Datagridview - DataGridViewImageColumn
Within the routine/job tracker it connects to the nitro load balancer api and pulls the data down. So when the tabcontrol/tabpage is clicked i want it to pull down the current information and not from minutes ago or first time it was pulled. Can a column be created as [System.Windows.Forms.DataGridViewImageColumn] ? I see the add control creates as [System.Windows.Forms.DataGridViewTextBoxColumn].
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: Datagridview - DataGridViewImageColumn
It does work when i don't set the datasource to $null. The clear was to make sure that the data being loaded was from current and not was there.
Re: Datagridview - DataGridViewImageColumn
Re-assigning the data source always replaces everything. Setting it to null removes all definitions including column.
If you don't assign columns and set the columns to autosize and generate then this would not matter. Either way works.
If you don't assign columns and set the columns to autosize and generate then this would not matter. Either way works.
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am