dynamically create gui elements based on csv contents.

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 5 years and 10 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
RARLINX1
Posts: 9
Last visit: Mon Feb 20, 2023 1:34 pm

dynamically create gui elements based on csv contents.

Post by RARLINX1 »

Hi guys.

I want to put together a loader/manager tool for lots of scripts and tools we use. I plan on having all the info for each tool to be sourced from a csv file out on the network some where. with this data populate my form with a listing for each row. similar to a product listing on an online store.
I plan to have this csv file listing: Script/Program Name, current Version, Download location, Install location, description and probably a thumbnail image location.

the Question is How: can I set it up so my form will dynamically create a panel containing a set of labels, image boxes and buttons for each row of the csv and preserve some kind of visual continuity?

Thanks,

Using : PowershellStudio2018
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dynamically create gui elements based on csv contents.

Post by jvierra »

You can do many things to generate forms from data but it is a very advanced set of techniques. Mostly you will need to determine what the panel looks like. I find this is best done with a paper and pencil. Grid paper is the best. Once you have thought out what your panel looks like then just build it in the designer.

Why do you think this needs to be dynamic and why don't you use a DataGridView?

Here are some articles that show ways to use data to automate forms.
http://tech-comments.blogspot.com/2017/ ... forms.html

The subform is dynamically generated in the example.
RARLINX1
Posts: 9
Last visit: Mon Feb 20, 2023 1:34 pm

Re: dynamically create gui elements based on csv contents.

Post by RARLINX1 »

pictures speak a thousand words right? (i hope)
Image


so im wanting image url/file inserted as source for the image box, name, version, details etc in to the relevant labels/text blocks and depending if already installed locally or not install/download/update or uninstall buttons adapt accordingly.
Setting all this in static panels and assigning its contents to line 1, 2 or 3 etc is easy enough, but im wanting to get it adding it itself so when ever the CSV is updated or have more added to it this will just add it in.

Its a Pretty thing.
Last edited by RARLINX1 on Thu May 17, 2018 8:20 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dynamically create gui elements based on csv contents.

Post by jvierra »

No image here.
RARLINX1
Posts: 9
Last visit: Mon Feb 20, 2023 1:34 pm

Re: dynamically create gui elements based on csv contents.

Post by RARLINX1 »

there we go ^^
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dynamically create gui elements based on csv contents.

Post by jvierra »

Simple. Just assign the CSV items to the controls. Assigning an image url to a picturebox will change the image. Assign text property on labels and textboxes.
RARLINX1
Posts: 9
Last visit: Mon Feb 20, 2023 1:34 pm

Re: dynamically create gui elements based on csv contents.

Post by RARLINX1 »

yes in a stactic panel I made in the form this will work just fine.

ill try and make convey this better, I can make it do that if i create and set a panel, with an image box etc. I can bake 10 panels like this and assign the data from the first 10 lines of the CSV
But this is all static. I need to grammatically generate the elements to then assign the data to.

I wanting to have a flowlayoutpanel, then for each line of the CSV it create and add a new panel with the data assigned from that line.
so that if i were to have 5 apps listed in the CSV it would stack 5 variations of the above example in the flowlayoutpanel, or if i had 20 lines in the CSV it would create 20 of them.
All without me having to create a panel to hold each one.

maybe like saying "here is a template, use it to create a listing for each line in the CSV and inset them in to the flowlayout panel"

I hope im making sense.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dynamically create gui elements based on csv contents.

Post by jvierra »

Did you look at the article I posted a link to. The subform I create is dynamic and generates the controls from the data. It will generate as many controls as needed for the current data record. It can be repeated.

I think your design may be a bit off and will be cumbersome. Use one form and databind it with forward and backwards buttons and the user can just step through.
RARLINX1
Posts: 9
Last visit: Mon Feb 20, 2023 1:34 pm

Re: dynamically create gui elements based on csv contents.

Post by RARLINX1 »

yes i did look at it, didnt seem to apply for what im going for. (perhaps im just too blind to see how to use it in my project)

Im not using any sub forms or anything, this is all in one window.

Open the app, it imports the CSV, gets images and external data, shows each applications/scripts data in a panel. within the flow panel of in the center of the main form.

similar to a websites product page:
Image
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dynamically create gui elements based on csv contents.

Post by jvierra »

Don't think of the subform as a subform but as a dynamically generated form. The same methods work in any form.
This topic is 5 years and 10 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