alaa

alaa

  • NA
  • 166
  • 50.9k

gridview autocomplete windows application c#

May 9 2015 6:59 AM
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

<pre lang="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;

                }

            }
}</pre>

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

Answers (2)