Skip to content

Gridview autocomplete windows application c#

alaa

Asked May 9, 2015, 2:59 AM EDT2 answers
Share
LinkedInX
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 ?

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.