How to set the textbox as AutoSuggest in WinForms GridControl?
AutoSuggest textbox
There is no direct support for AutoSuggest in TextBox cell. ComboBox cell only contains AutoSuggest support. Therefore, to make a textbox cell as AutoSuggest textbox, modify the ComboBox cell to work like TextBox cell.
Solution
You can change the appearance of combo box cell like text box cell by disabling the dropdown button using the ShowButtons property. You can achieve AutoSuggest textbox by setting the AutoCompleteInEditMode property. By default, the suggested items can be dropped down while pressing the dropdown button of ComboBox. Hence, you can display the dropdown items while entering the text by handling the CurrentCellKeyPress event.
In the provided sample, 2nd row 1st column is set as AutoSuggest textbox.
C#
this.grid.CoveredRanges.Add(GridRangeInfo.Cells(1, 1, 1, 1)); this.grid[1, 1].CellValue = "AutoSuggest TextBox"; this.grid[1, 1].Font.Bold=true; //Setting Combobox Celltype this.grid[2, 1].CellType = GridCellTypeName.ComboBox; //Hidding the DropDown button to show it as TextBox cell this.grid[2, 1].ShowButtons = GridShowButtons.Hide; //To make cell as AutoSuggest this.grid[2, 1].AutoCompleteInEditMode = GridComboSelectionOptions.AutoSuggest; this.grid[2, 1].ChoiceList = choice; this.grid.CurrentCellKeyPress += new KeyPressEventHandler(grid_CurrentCellKeyPress); void grid_CurrentCellKeyPress(object sender, KeyPressEventArgs e) { if (this.grid.CurrentCell.Renderer is GridComboBoxCellRenderer) this.grid.CurrentCell.ShowDropDown(); }
VB
Me.gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(1,1,1,3)) Me.gridControl1(1, 1).CellValue = "AutoSuggest TextBox(2,1)" Me.gridControl1(1, 1).Font.Bold = True 'Setting Combobox Celltype Me.gridControl1(2, 1).CellType = GridCellTypeName.ComboBox 'Hiding the DropDown button to show it as TextBox cell Me.gridControl1(2, 1).ShowButtons = GridShowButtons.Hide 'To make the cell as AutoSuggest Me.gridControl1(2, 1).AutoCompleteInEditMode = GridComboSelectionOptions.AutoSuggest Me.gridControl1(2, 1).ChoiceList = choice AddHandler gridControl1.CurrentCellKeyPress, AddressOf gridControl1_CurrentCellKeyPress End Sub Private Sub gridControl1_CurrentCellKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) If TypeOf Me.gridControl1.CurrentCell.Renderer Is GridComboBoxCellRenderer Then Me.gridControl1.CurrentCell.ShowDropDown() End If End Sub
The following screenshot illustrates the output.
Figure 1: AutoSuggest TextBox