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.
This topic is 3 years and 3 months 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
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

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.     $Header = ('a', 'b', 'c').Where{ $Row.$_ -eq 1}
  3.     If ($Header.Count -eq 1) { $Header }
  4. }
$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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Best way to present data

Post by mattys »

OK
I will keep trying
Thank you for your time.
This topic is 3 years and 3 months 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