)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set the textbox as AutoSuggest in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: March 17, 2015 |
Last Revised Date: December 19, 2019

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.

AutoSuggest textbox in GridControl

Figure 1: AutoSuggest TextBox

Samples:

C#: AutoSuggest_CS

VB: AutoSuggest_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon