Page 1 of 2

dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 6:58 am
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

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 7:08 am
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.

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:12 am
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.

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:16 am
by jvierra
No image here.

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:20 am
by RARLINX1
there we go ^^

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:26 am
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.

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:44 am
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.

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:49 am
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.

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 8:58 am
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

Re: dynamically create gui elements based on csv contents.

Posted: Thu May 17, 2018 9:14 am
by jvierra
Don't think of the subform as a subform but as a dynamically generated form. The same methods work in any form.