How can we put autosuggest combobox in datagridview column1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ankitrathore
    New Member
    • May 2010
    • 4

    How can we put autosuggest combobox in datagridview column1

    Hi Guys,

    Suppose I put one combobox in first column of datagrid,
    then How can we made combobox act as a autosuggest from access 2007 database only,


    Please help me,


    Regard's
    Ankit
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    have you tried the properties AutoCompleteCus tomSource,AutoC omplete mode,AutoComple Source properties of a combobox

    Comment

    • ankitrathore
      New Member
      • May 2010
      • 4

      #3
      Originally posted by ThatThatGuy
      have you tried the properties AutoCompleteCus tomSource,AutoC omplete mode,AutoComple Source properties of a combobox
      Yes I was already use that,
      but its not working,

      Please just check it at once with my snippet in which I was trying to put autosuggest text box only:-


      using System;
      using System.Collecti ons.Generic;
      using System.Componen tModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows. Forms;
      using System.Data.Ole Db;


      namespace DatagridExample
      {
      public partial class Form1 : Form
      {
      AutoCompleteStr ingCollection scAutoComplete = new AutoCompleteStr ingCollection() ;

      public Form1()
      {
      //AutoCompleteStr ingCollection scAutoComplete = new AutoCompleteStr ingCollection() ;

      InitializeCompo nent();
      }

      private void Form1_Load(obje ct sender, EventArgs e)
      {
      string strCon = @"Provider=Micr osoft.ACE.OLEDB .12.0;Data Source=DBAccoun t.accdb";
      OleDbDataAdapte r da = new OleDbDataAdapte r();
      OleDbConnection conn = new OleDbConnection ();
      DataSet ds = new DataSet();
      conn = new OleDbConnection (strCon);

      da = new OleDbDataAdapte r("Select *from Bill", conn);
      da.Fill(ds, "Bill");


      dataGridView1.D ataSource = ds.Tables("Bill ");


      OleDbCommand cmd = new OleDbCommand("S elect ItmCode from Bill", conn);
      OleDbDataReader reader = new OleDbDataReader ();
      OleDbDataReader dr = new OleDbDataReader ();
      conn.Open();
      dr = cmd.ExecuteRead er;
      while (dr.Read)
      {
      scAutoComplete. Add(dr.GetStrin g(0));

      }
      conn.Close();



      }


      private void dataGridView1_E ditingControlSh owing(object sender, DataGridViewEdi tingControlShow ingEventArgs e)
      {
      if (dataGridView1. CurrentCell.Col umnIndex == 1 && e.Control is TextBox)
      {
      ((TextBox)e.Con trol).AutoCompl eteMode = AutoCompleteMod e.SuggestAppend ;
      ((TextBox)e.Con trol).AutoCompl eteSource = AutoCompleteSou rce.CustomSourc e;
      ((TextBox)e.Con trol).AutoCompl eteCustomSource = scAutoComplete;
      }
      }
      }
      }
      =============== =============== ======
      I got some error on these below line:-

      1. dataGridView1.D ataSource = ds.Tables("Bill ");

      " Error 1 Non-invocable member 'System.Data.Da taSet.Tables' cannot be used like a method."


      2. OleDbDataReader dr = new OleDbDataReader ();
      ("Error 2 The type 'System.Data.Ol eDb.OleDbDataRe ader' has no constructors define ")


      please help in this snippet........ ....

      Comment

      • ThatThatGuy
        Recognized Expert Contributor
        • Jul 2009
        • 453

        #4
        you can try this snippet....i worked it on and it worked for me...
        in DataGridView.Ed itingControlSho wing event
        Code:
                    if (e.Control is DataGridViewComboBoxEditingControl)
                    {
                       ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
                      ((ComboBox)e.Control).AutoCompleteCustomSource.AddRange(new string[] { "apple", "bat", "cat", "doggie" });
                      ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.CustomSource;
                       ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
        
                    }

        Comment

        • ankitrathore
          New Member
          • May 2010
          • 4

          #5
          Originally posted by ThatThatGuy
          you can try this snippet....i worked it on and it worked for me...
          in DataGridView.Ed itingControlSho wing event
          Code:
                      if (e.Control is DataGridViewComboBoxEditingControl)
                      {
                         ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
                        ((ComboBox)e.Control).AutoCompleteCustomSource.AddRange(new string[] { "apple", "bat", "cat", "doggie" });
                        ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.CustomSource;
                         ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
          
                      }
          Thanks it works now,

          Comment

          Working...