DataGridView Question

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 2 years and 8 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
PowerShell_Ham
Posts: 1
Last visit: Tue Feb 13, 2024 9:32 am

DataGridView Question

Post by PowerShell_Ham »

Hey All,

I have a tool I've been working on to dynamically populate AD security groups from a specific OU into a CheckedListBox. From here I can quickly manage adding groups to one or more users. This method is working great currently but I would like to add the ability to filter with a textbox to quickly find certain groups when needed. I've searched around and found posts that state this isn't possible with CheckedListBox without retaining the status of boxes that get filtered out.

After more searching, I was able to put together a nice DataGridView as a test although I'm not super familiar with them yet. I can filter the group names and check the boxes next to them but can't figure out how to get the checked group names to output for use in a function. Can anyone possibly point me to a good example or resource? Or suggest a better way to accomplish this?


Thank you!
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

Re: DataGridView Question

Post by Domtar »

hi,

I was able to make this by using a Textbox control and the following code;

Code: Select all

$textboxFilter_TextChanged={
	for ($i = 0; $i -lt $datagrid.RowCount; $i++)
	{
		if ($datagrid.Rows[$i].Cells[0].value -notlike "*$($textboxFilter.text)*")
		{ $datagrid.Rows[$i].Visible = $false }
		else
		{ $datagrid.Rows[$i].Visible = $true }
	}
}
that works perfectly for me!
This topic is 2 years and 8 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