Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to search in datagridview combobox in c# like '%text%' with sql
please help me i need this code to my project,please...

for example:
if in combobox has four name like ('Book','Computer','Car','Pen')
if insert (' o ') in combobox
the result must be show (Book, Computer).
how to write this code,please answer me.thanks.
i'm waiting...
Posted
Updated 6-Apr-14 5:50am
v2
Comments
[no name] 6-Apr-14 12:26pm    
Do you mean that you want an "autocomplete" combobox?
Abinash_Sahoo 6-Apr-14 12:45pm    
Are you using some control like, Ajax Autocomplete or jQuery Autocomplete or any Telerik ASP.NET control?

Use a filter on the BindingSource - BindingSource.Filter Property [^].
For e.g.
bs.Filter = dgv1.Columns[1].HeaderText.ToString() + " LIKE '%" +  text1.Text + "%'";
 
Share this answer
 
I shall show you the idea through an example:
C#
using System;

public class Program
{
    public static void Main()
    {
        // an array of combo values
        string[] comboString = {"book", "computer", "car", "pen"};

        // search string from user
        string searchString = "o";

        // array for storing matching
        string[] matchString = {};

        foreach (var word in comboString)
        {
            if (word.Contains(searchString))
                Console.WriteLine(word);
        }
    }
}
 
Share this answer
 
v3

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