Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have agridview i hope to make auto complete for only one colum but it works with all row cells all the cells are textbox i use that code

C#
  public AutoCompleteStringCollection AutoCompleteLoad()
        {

            AutoCompleteStringCollection str = new AutoCompleteStringCollection();

            foreach (DataRow row in dt.Rows)
            {
                str.Add(Convert.ToString(row[1]));
            }
            return str;
        }

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {            
            int column = dataGridView1.CurrentCell.ColumnIndex;

            string headerText = dataGridView1.Columns[1].HeaderText;

            if (headerText.Equals("pro"))
            {

                TextBox tb = e.Control as TextBox;

                if (tb != null)
                {

                    tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                    tb.AutoCompleteCustomSource = AutoCompleteLoad();

                    tb.AutoCompleteSource = AutoCompleteSource.CustomSource;

                }

            }
}


i make to only only column but still work with all cells how can i solve it ?
Posted

1 solution

Refer - Textbox Autocomplete in a DataGridView Winform[^].
Quote:
Your if condition is just checking if the user has currently selected the third column.

Do you want to make all that column editable? or just one cell in the currently selected row? How is the edit triggered by another button off the form? In this case when the edit becomes active any cell could be selected?

You will need to index into the correct column and set it to have the autocomplete on.
 
Share this answer
 
Comments
ost3z 9-May-15 15:23pm    
thats good thanks i change to index but still (i need three textbox to be editable)

int column = dataGridView1.CurrentCell.ColumnIndex;
string headerText = dataGridView1.Columns[1].HeaderText;

if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
TextBox tb = e.Control as TextBox;

if (tb != null)
{
tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tb.AutoCompleteCustomSource = AutoCompleteLoad();
tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
else
{
tb.AutoCompleteCustomSource = null;
}

}

i try it but still the three works as autocomblete desbite i indexed it for index 2 how it can be solved
Can you debug and see what is happening? You will surely find the fault.
ost3z 10-May-15 8:45am    
the strange thing in debugging it works fine 100 % but the other textboxes still have autocomplete the code fire when the columnindex == 2 thats what i need but the others textboxes still autocomplete ????
Member 14186924 1-Aug-19 11:13am    
Can we do this for the datagridview text box autocomplete for matching string?
I have not tried. Are you facing any issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900