0

This is how I am populating my combobox from database which is large quantity. How i am search from list items in combobox as suggested not start from beginning it search also substring found inside of the string. and show all matching results in suggested list of combobox

{
    SqlConnection connection = DBConnectivity.getConnection();
    SqlCommand command;
    string query;
    DataSet dataset;
    DataTable datatable;
    SqlDataAdapter adapter;
    SqlDataReader reader;
    string[] ProductNameList;

    public productform()
    {
        InitializeComponent();


    }

    //------------Form load Events and functions-----------------------------
    DataSet dataset2 = new DataSet();  
    ClassesAll.PartyandProductClass PartyandProducts = new ClassesAll.PartyandProductClass();
    private void productform_Load(object sender, EventArgs e)
    {

        try
        {
            // events for loading partytype broker on load

            string query2 = "SELECT productNameUR, id FROM product";
            SqlCommand command2 = DBConnectivity.getCommandForQuery(query2, connection);

            SqlDataAdapter adapter2 = new SqlDataAdapter(command2);
            adapter2.Fill(dataset2);
            int result = command2.ExecuteNonQuery();
            this.cBjins.DisplayMember = "productNameUR";
            this.cBjins.ValueMember = "id";

            DataRow datarow1 = dataset2.Tables[0].NewRow(); 
            datarow1["productNameUR"] = "Select Product";
            dataset2.Tables[0].Rows.InsertAt(datarow1, 0);
            this.cBjins.DataSource = dataset2.Tables[0];


        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

Suggest me a solution.

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
  • I think this is already addressed [here](https://stackoverflow.com/questions/11780558/c-sharp-winforms-combobox-dynamic-autocomplete) mainly look at 3rd answer – rahulaga-msft Feb 26 '18 at 04:11
  • it start search from beginning, i want if string match in the medal also give in suggestion – waqas rafi Feb 26 '18 at 04:43
  • [Here](https://www.codeproject.com/Tips/631196/ComboBox-with-Suggest-Ability-based-on-Substring-S) is a good article on custom Combobox with substring searching ability. – Khandakar Rashed Hassan Sep 01 '20 at 14:39

0 Answers0