Search as you type
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.
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.
- alvalenz79
- Posts: 36
- Last visit: Fri Jan 26, 2018 11:23 am
Search as you type
Is there a way to filter as you type? I want the function to search my datagrid without using a button.
Re: Search as you type
You would have to write custom search code. This can be done with a datatable and by setting the filter in the dataview. Performance will not be good for other than very small datasets.
Consider using a listbox with autocomplete.
Consider using a listbox with autocomplete.
- alvalenz79
- Posts: 36
- Last visit: Fri Jan 26, 2018 11:23 am
- alvalenz79
- Posts: 36
- Last visit: Fri Jan 26, 2018 11:23 am
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Search as you type
If you're loading your datagridview with a datatable you can filter the results. I assume you can do it on the textchanged event but it may be slow.
Where $dt is my datatable.
textchanged event
$filter = $textbox1.text
$DT.defaultview.rowfilter = "hostname like '%$filter%'"
Where $dt is my datatable.
textchanged event
$filter = $textbox1.text
$DT.defaultview.rowfilter = "hostname like '%$filter%'"
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Search as you type
for example.
- $form1_Load={
- $Data = Get-process
- $script:dt = ConvertTo-DataTable -InputObject $data
- $datagridview1.DataSource = $dt
- }
- $textbox1_TextChanged={
- $filter = $textbox1.text
- $DT.defaultview.rowfilter = "name like '%$filter%'"
- }
- alvalenz79
- Posts: 36
- Last visit: Fri Jan 26, 2018 11:23 am
Re: Search as you type
@ dan
I have modified my script to mimic what you recommend. Lines 278 -293
line 367-371
The property 'rowfilter' cannot be found on this object. Verify that the property exists and can be set.
I have modified my script to mimic what you recommend. Lines 278 -293
$form1_Load={
$Data = Get-process
$script:dt = ConvertTo-DataTable -InputObject $data
$datagridview1.DataSource = $dt
}
line 367-371
I get he following error when I type anything in the box.
$textbox1_TextChanged={
$filter = $textbox1.text
$DT.defaultview.rowfilter = "name like '%$filter%'"
The property 'rowfilter' cannot be found on this object. Verify that the property exists and can be set.
- Attachments
-
- ADupdaterHelp.psf
- (29.42 KiB) Downloaded 156 times
Re: Search as you type
Here is the technique:
- [System.Data.DataTable]$dt = Get-process | ConvertTo-DataTable
- $datagridview1.DataSource = $dt
- $dt.DefaultView.RowFilter = "Name like '%joe%'"
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am