Need Help with DGV and Comboboxes

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 1 year and 6 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
ARM_LeaT
Posts: 3
Last visit: Thu Aug 03, 2023 1:00 am

Need Help with DGV and Comboboxes

Post by ARM_LeaT »

Product, version and build: Powershell Studio 2022, 5.8.206
Operating system: W10 21H2

Hello together :)
I am pretty new to Powershell and especially in creating GUIs etc. I need help with the following topic:
I want to create a GUI with two datagrids that contain information that I have gathered from a json file. Some of this info is plain text and this I have already been able to store in a data table and also to view in the first datagrid (jeah! :) )

Now the tricky bit:
sometimes a field from the json contains only one option of many and the user should be able to reselect it via a combobox. But it's not like all fields have the same options. Every combobox has its own items.

So I need a datagrid that looks like this:

Code: Select all

header: Column 1 | Column 2
row 1: field 1 (fixed fieldname that comes from the json and is not adjustable) | combobox with some options and a selected one that is matching the info from the json
I hope someone can help me with this topic! Thanks in advance!

btw. I have created the first datagrid with the simple text fields like this:

Code: Select all

## - Create DataTable:
	$table = New-Object System.Data.DataTable;
	
	## - Defining DataTable object columns and rows properties:
	# - Column1 = "Jira Field".
	$column = New-Object System.Data.DataColumn;
	$column.DataType = [System.Type]::GetType("System.String");
	$column.ColumnName = "Jira Field";
	$column.ReadOnly = $true;
	$table.Columns.Add($column);
	
	# - Column2 = "Value".
	$column = New-Object System.Data.DataColumn;
	$column.DataType = [System.Type]::GetType("System.String");
	$column.ColumnName = "Value";
	$column.ReadOnly = $false;
	$table.Columns.Add($column);
	
	## - Add Records to datatable dataset object:
	
	$row = $table.NewRow();
	$row["Jira Field"] = "Package Name";
	$row["Value"] = $global:packageName;
	
	$table.Rows.Add($row);
	
	etc. ....
	 
	## - Save changes to the table:
	$table.AcceptChanges();
	
	## - Display custom data created:
	$datagridviewJiraDataFreeText.DataSource = $table;
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 times

Re: Need Help with DGV and Comboboxes

Post by brittneyr »

[Topic moved by moderator to PowerShell GUIs forum]
Brittney
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need Help with DGV and Comboboxes

Post by jvierra »

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

Re: Need Help with DGV and Comboboxes

Post by jvierra »

Here is the documentation for the DGVComboBoxColumn:

https://docs.microsoft.com/en-us/dotnet ... esktop-6.0

You want to put the items into the "Items" collection for the column.
ARM_LeaT
Posts: 3
Last visit: Thu Aug 03, 2023 1:00 am

Re: Need Help with DGV and Comboboxes

Post by ARM_LeaT »

Thanks for the links :)

However this hasn't worked for me (with my current skill level) to setup every combobox with different items in it. So I have dumped the idea of the grid and have just added individual combobox controls which are easier for me to handle.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need Help with DGV and Comboboxes

Post by jvierra »

You can only define the list once per DGV column. It is defined when you create the column. It is just one property that is assigned once. Why is that hard?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need Help with DGV and Comboboxes

Post by jvierra »

I should also note that once you assign the comboboxcolumn lists you do not have to write any code. The DGV does all of the rest automatically.
ARM_LeaT
Posts: 3
Last visit: Thu Aug 03, 2023 1:00 am

Re: Need Help with DGV and Comboboxes

Post by ARM_LeaT »

That is the thing: I need comboboxes with different items for each row and according to what I have read so far: "not possible"
That's fine for me, I found a solution that works for me and that is sufficient for my purpose :)
This topic is 1 year and 6 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