Autocomplete datagridview inside datagridview

ankit goel 766 Reputation points
2022-12-08T13:28:05.883+00:00

I am working on a c# windows based project where I am trying to pop up a datagridview containing suggestive words whenever I enter the specified cell ie Textboxcolumn of datagridview .Can someone please share the details how to do so.

Developer technologies .NET Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 25,296 Reputation points
    2022-12-09T03:09:20.767+00:00

    @ankit goel , Welcome to Microsoft Q&A, based on my test, I find that Textboxcolumn may be not a good choice to show the suggestive words. I recommend that you used DataGridViewComboBoxColumn.

    Here is a code example you could refer to.

     private void Form1_Load(object sender, EventArgs e)  
            {  
      
                DataGridViewComboBoxColumn column =  
                 new DataGridViewComboBoxColumn();  
                {  
                    column.DataPropertyName = "Name";  
                    column.HeaderText = "Name";  
                    column.DropDownWidth = 160;  
                    column.Width = 90;  
                    column.MaxDropDownItems = 3;  
                    column.FlatStyle = FlatStyle.Popup;  
                }  
                column.Items.Add("Jack");  
                column.Items.Add("Jason");  
                column.Items.Add("John");  
                dataGridView1.Columns.Insert(0,column);  
      
            }  
            private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)  
            {  
                if (dataGridView1.CurrentCell.ColumnIndex == 0)  
                {  
                    ComboBox combo = e.Control as ComboBox;  
      
                    if (combo == null)  
                        return;  
      
                    combo.DropDownStyle = ComboBoxStyle.DropDown;  
                    combo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;  
                }  
            }  
    

    Result:

    268774-image.png

    Hope this could help you.

    Best Regards,
    Jack

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.