datagridview & table

Ask your PowerShell-related questions, including questions on cmdlet development!
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 2 years and 1 month 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
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

datagridview & table

Post by Domtar »

hi all,

I've created a GUI where I display a DataGridView bound to a table. I load all the desired values into the Table and successfully display it in my DGV.

The data is the computers from AD with their location.

Now, I'm trying to display some values depending on a criteria. For example, I'd like to show only the comps located in New York. I've added a comboBox with the different values for Location.

can someone please give me an example of code on how to display only the values I wish?

thanks!

edit: this line of code:

$datagridview1.DataSource.defaultview.rowfilter = "Site -eq '$(($combobox1.SelectedItem).ToString())'"

gives me this error that I still don't understand.

ERROR: Exception setting "rowfilter": "Syntax error: Missing operand after ''NY'' operator."

I feel like I'm getting close though.

edit2: got it!

$datagridview1.DataSource.defaultview.rowfilter = "Site like '$($combobox1.SelectedItem)'"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: datagridview & table

Post by jvierra »

You have to use the "RowFilter" property of the DataView.

See: https://docs.microsoft.com/en-us/dotnet ... -rowfilter
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: datagridview & table

Post by jvierra »

Simple example:

$datatable1.DefaultView.RowFilter = 'Site = ' + $combobox1.SelectedItem
This topic is 2 years and 1 month 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