Create a DataGridView and export to a csv

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 6 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
User avatar
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time

Re: Create a DataGridView and export to a csv

Post by ramses147 »

Something like these, i search on google but i found only C++ applications, few examples with powershell
Attachments
2.png
2.png (22.68 KiB) Viewed 2181 times
1.jpg
1.jpg (72.73 KiB) Viewed 2181 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Create a DataGridView and export to a csv

Post by jvierra »

You can add all user to a combo box when you define the column.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Create a DataGridView and export to a csv

Post by jvierra »

To sure search and sort functions use the DefaultDataView on the data table object.

$DataGridView.DefaultDataView.Find (or Filter).

Here is the only example I have:
Attachments
Demo-DGVSortFormat.ps1
(7.76 KiB) Downloaded 117 times
User avatar
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time

Re: Create a DataGridView and export to a csv

Post by ramses147 »

jvierra wrote:You can add all user to a combo box when you define the column.
Ok no problem now to add a column, but have you got a sample how to insert it ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Create a DataGridView and export to a csv

Post by jvierra »

Just create nd add a ComboBox column. Set the datasource, datapropertyname and displaymember as needed.
User avatar
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time

Re: Create a DataGridView and export to a csv

Post by ramses147 »

This is working, but my problem is working when i insert COMPUTERNAME in the filter, with DOMAIN ACCOUNT ( that has a space between the 2 words ), doesn't work

  1. $buttonFilter.add_Click({
  2. $datagridview.DataSource.DefaultView.RowFilter = "DOMAIN ACCOUNT LIKE '$($textboxFilter.Text)*'"  })
User avatar
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time

Re: Create a DataGridView and export to a csv

Post by ramses147 »

solved with [], but i can't add the second and third filter
  1. $datagridview.DataSource.DefaultView.RowFilter = "COMPUTERNAME LIKE '$($textboxFilter.Text)*'"
  2. $datagridview.DataSource.DefaultView.RowFilter = "[LOCAL ACCOUNT] LIKE '$($textboxFilter.Text)*'"
  3. $datagridview.DataSource.DefaultView.RowFilter = "[DOMAIN ACCOUNT] LIKE '$($textboxFilter.Text)*'"
User avatar
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time

Re: Create a DataGridView and export to a csv

Post by ramses147 »

Found a solution :-)
Public it below so it will be useful for those who will encounter my own problem
  1. $datagridview.DataSource.DefaultView.RowFilter = "COMPUTERNAME LIKE '$($textboxFilter.Text)*' OR [LOCAL ACCOUNT] LIKE '$($textboxFilter.Text)*' OR [DOMAIN ACCOUNT] LIKE '$($textboxFilter.Text)*'"
User avatar
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time

Re: Create a DataGridView and export to a csv

Post by ramses147 »

I try to insert combox, and ok, no problem, but when i export there are no values related at combox
maybe binding with datatable.. but i can't find the right code
  1. $dt = New-Object System.Data.DataTable
  2.  
  3. $i = $dataGridView.Columns.Add('COMPUTERNAME', 'COMPUTERNAME')
  4. $c = $dataGridView.Columns[$i]
  5. $c.width = 150
  6. $c.DataPropertyName = 'COMPUTERNAME'
  7. [void]$dt.Columns.Add($c.DataPropertyName)
  8.  
  9. $i = $dataGridView.Columns.Add('LOCAL ACCOUNT', 'LOCAL ACCOUNT')
  10. $c = $dataGridView.Columns[$i]
  11. $c.width = 150
  12. $c.DataPropertyName = 'LOCAL ACCOUNT'
  13. [void]$dt.Columns.Add($c.DataPropertyName)
  14.  
  15.  
  16. $Column3 = New-Object System.Windows.Forms.DataGridViewComboBoxColumn
  17. $Column3.HeaderText = "DOMAIN ACCOUNT"
  18. $Column3.Width = 150
  19. $Column3.HeaderCell.Style.Alignment = "middlecenter"
  20. $Column3.DefaultCellStyle.Alignment = "middlecenter"
  21. [void]$DataGridView.Columns.Add($Column3)
  22. $UserList= Get-ADUser -Filter * -SearchBase 'OU=USERS,DC=DOM,DC=LOCAL' | Select -ExpandProperty SamAccountName
  23. [void]$Column3.Items.AddRange($UserList)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Create a DataGridView and export to a csv

Post by jvierra »

You have to create a ComboBox column cell first then add it to columns.
This topic is 6 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