Click here to Skip to main content
16,017,954 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I have auto complete text box in Windows application where in it is populating the list from database. But typing it is filtering only starting with first character. How should i able to provide option to search in middle of the auto complete text as a LIKE operator.

When my user start typing jas all the list in between matches of jas also should be filtered and displayed.
Thanks in advance

i was wrote that but this code did not work
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace auto_complete_textbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       AutoCompleteStringCollection ACSC = new AutoCompleteStringCollection();
       
        private void textBox1_TextChanged(object sender, EventArgs e)
        {


            try
            {

                SqlCommand sqm = new SqlCommand("SELECT Location FROM DBO.Incident WHERE Location LIKE '%@Location%' ", new SqlConnection("data source=.;database=A police control system;uid=sa;pwd=sql"));
                sqm.Connection.Open();
                sqm.Parameters.Add("@Location", SqlDbType.NVarChar).Value = textBox1.Text;
                SqlDataReader sdr = sqm.ExecuteReader();
                if (sdr.HasRows == true)
                {
                    while (sdr.Read())
                    {
                      
                         ACSC.Add(sdr["Location"].ToString());

                    }

                }
                sqm.Connection.Close();
                textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
                textBox1.AutoCompleteCustomSource = ACSC;

            }
            catch (Exception ex)
            {

              messagebox.show(ex.message);
            }
          
           
        }
Posted
Updated 11-Aug-13 9:10am
v5
Comments
[no name] 11-Aug-13 14:54pm    
So you want us to tell you how to change your code without seeing what you have done?
[no name] 11-Aug-13 15:09pm    
http://stackoverflow.com/questions/251276/howto-parameters-and-like-statement-sql
omidv 11-Aug-13 15:31pm    
i saw address but not any solution for my question in there
Dave Kreskowiak 11-Aug-13 21:26pm    
Using the SA account to do this?? Wow, what a security risk! Nice job!

1 solution

plese refere this link-->

http://www.codeproject.com/Articles/251110/AutoComplete-TextBox-with-substing-search-similar
 
Share this answer
 

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