autocomplete in datagridview

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 2 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
purchasingITScordis
Posts: 2
Last visit: Wed Nov 29, 2023 4:01 am

autocomplete in datagridview

Post by purchasingITScordis »

hello everyone and a happy new year

i have a datagridview control and in of the cells i would like to use the autocomplete feature

i have played around with the event editcontrolshowing but cant get it to show in the cell


here is my code
  1. $DGVtimeAttendance_EditingControlShowing = [System.Windows.Forms.DataGridViewEditingControlShowingEventHandler]{
  2.    
  3.     $queryGetaLLuSERS = @"
  4.         SELECT CONCAT(firstname,' ',lastname) AS Employee
  5.         FROM tbl_user
  6. "@
  7.     $queryGetaLLuSERS = sql_query -Query $queryGetaLLuSERS
  8.     $getheaderText = $DGVtimeAttendance.Columns[1].HeaderText
  9.     if ($getheaderText -eq 'Employee')
  10.     {
  11.         #$getvalueChanged = $this.Rows[$_.RowIndex].Cells[$_.ColumnIndex].value
  12.         #Write-Host $getvalueChanged
  13.         $autotext = New-Object System.Windows.Forms.DataGridViewTextBoxEditingControl
  14.         $autotext.AutoCompleteMode = 'Suggest'
  15.         $autotext.AutoCompleteSource = 'CustomSource'
  16.         $autotext.AutoCompleteCustomSource.AddRange($queryGetaLLuSERS.employee)
  17.         $DGVtimeAttendance.Controls.add($autotext)
  18.         #$_.Control.autocompleteMode = 'Suggest'
  19.         Write-Host $_
  20.      }
  21. } #end DGVtimeAttendance_EditingControlShowing
purchasingITScordis
Posts: 2
Last visit: Wed Nov 29, 2023 4:01 am

Re: autocomplete in datagridview

Post by purchasingITScordis »

hello everyone

for someone elses reference i have found the solution with the help from stackoverflow

changed the if statement to
  1.     if ($getheaderText -eq 'Employee')
  2.     {
  3.         $this.EditingControl.AutoCompleteMode = [System.Windows.Forms.AutoCompleteMode]::Suggest
  4.         $this.EditingControl.AutoCompleteSource = [System.Windows.Forms.AutoCompleteSource]::CustomSource
  5.         $this.EditingControl.AutoCompleteCustomSource.AddRange(($queryGetaLLuSERS.employee))
  6.      }
This topic is 2 years and 2 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