Datagridview DataTable Convert Column to Image

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 6 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Mabilode
Posts: 5
Last visit: Thu Feb 22, 2024 6:13 am

Datagridview DataTable Convert Column to Image

Post by Mabilode »

So I'm a bit Stumped right now,
I Need to set the Datasource because its Way easier to Search in a DataGrid and I need the Search fonctionnality to work.

So im loading a WMI Object Based on SCCM
In which there is a String that is the image of the Program.
its a String and Normaly I would use [System.Convert]::FromBase64String($item) To Convert the Value
But Since I use datasource I really have no Idea how to modify the Column type of the DatagridView and Also how to Convert the value in the Datasource
Here is the code that I have as of right now
  1. $CCMApplications = get-wmiobject -computername $Computername -query "SELECT * FROM CCM_Application where ApplicabilityState = 'Applicable'" -namespace "ROOT\ccm\clientsdk" | select icon, name, Publisher, SoftwareVersion, installstate
  2.     $Data = ConvertTo-DataTable $CCMApplications
  3.     foreach ($item in $Data.icon)
  4.     {
  5.         $Icon = [System.Convert]::FromBase64String($item)
  6.         $item = $Icon
  7.     }
  8.     $datagridviewApplications.AutoGenerateColumns = $false
  9.     $datagridviewApplications.Columns.Add("ColumnAppIcon", "")
  10.     $datagridviewApplications.Columns["ColumnAppIcon"].DataPropertyName = "icon"
  11.     $datagridviewApplications.Columns.Add("ColumnAppName", "Name")
  12.     $datagridviewApplications.Columns["ColumnAppName"].DataPropertyName = "name"
  13.     $datagridviewApplications.Columns.Add("ColumnAppPublisher", "Publisher")
  14.     $datagridviewApplications.Columns["ColumnAppPublisher"].DataPropertyName = "Publisher"
  15.     $datagridviewApplications.Columns.Add("ColumnAppVersion", "Version")
  16.     $datagridviewApplications.Columns["ColumnAppVersion"].DataPropertyName = "SoftwareVersion"
  17.     $datagridviewApplications.Columns.Add("ColumnAppStatus", "Status")
  18.     $datagridviewApplications.Columns["ColumnAppStatus"].DataPropertyName = "installstate"
  19.     $datagridviewApplications.DataSource = $Data
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datagridview DataTable Convert Column to Image

Post by jvierra »

If the Icon is a base64 encoded binary icon then you need to convert it to a byte array. You are returning it as a string.

Post a sample base64 string and I will give you an example.
This topic is 6 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked