Best way to present data

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Post Reply
mattys
Posts: 36
Joined: Mon Dec 30, 2019 10:58 am

Best way to present data

Post by mattys »

I have an object array ($data) that outputs like this.
a
c
b
b
c
a
b
a
a
c

For 'a' I want to present color green
'b' I want to present color yellow
'c' I want to present color Red.
In my Form I want to have the colors horizontal like this..
Image

My first thought is datagridview with colored cells, but am having difficulty getting started. So far all Im able to output in a datagridview comes out vertical with length of letters...
  1.  $datagridview1.DataSource = ConvertTo-DataTable $data
Any input is appreciated

Thanks

jvierra
Posts: 14666
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Best way to present data

Post by jvierra »

Hello. What you are asking is too vague. You will need to supply more of your code and specific issues or errors.
You cannot convert an array into a DataTable. You wil need to use something with a header or just create rows from the array.
To specify colors based on cell contents you will need to use the "CellPainting" event.

mattys
Posts: 36
Joined: Mon Dec 30, 2019 10:58 am

Re: Best way to present data

Post by mattys »

OK
Thanks for assisting jvierra.
Basically I have a CSV file ($data) that is formatted as this:
date,a,b,c
10,1,0,0
11,0,0,1
12,0,1,0
13,0,1,0
14,0,0,1
15,1,0,0
16,0,1,0
17,1,0,0
18,1,0,0
19,0,0,1

I iterate through each row ($Row) in the data table ($data)

Collect all the concerned columns ('a', 'b', 'c') that meet my requirements (e.g. -eq 1)
  1. $output = ForEach ($Row in $Data) {
  2.  
  3.     $Header = ('a', 'b', 'c').Where{ $Row.$_ -eq 1}
  4.  
  5.     If ($Header.Count -eq 1) { $Header }
  6.  
  7. }
$Output returns this
a
c
b
b
c
a
b
a
a
c

Im trying to get this $output into a single line, horizontal grid, where then I can color the cells with a CellPainting event based on cell content.
In my Form I want to have the colors horizontal like this..
Image
Thank you for your time.

jvierra
Posts: 14666
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Best way to present data

Post by jvierra »

So you don't yhave an array of one column and your original statements are not even close to what you are trying to do.

To colorize columns just use the "CellPainting" event to set the cell color. Read the documentation for the event and it will explain how to use the event to alter the format of the cell. There is no need to write functions or other methods. That is why we have that event and it is the easiest way to manage this property.

A data table does not have color and a CSV does not have color. Only the cell has color.

mattys
Posts: 36
Joined: Mon Dec 30, 2019 10:58 am

Re: Best way to present data

Post by mattys »

OK
I will keep trying
Thank you for your time.

Post Reply