Solved

Incremental Search in CombodBox

Posted on 2011-03-06
16
890 Views
Last Modified: 2012-05-11
I bind combobox through dattable.

how can i add incremental search features in combobox..

Thanks
0
Comment
Question by:Kalpesh Chhatrala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
16 Comments
 
LVL 12

Expert Comment

by:starlite551
ID: 35045805
What Exactly are you trying to achieve can you elaborate on the question..?
0
 
LVL 16

Author Comment

by:Kalpesh Chhatrala
ID: 35045816
incremental search means result will be filter on each and every keypress.
0
 
LVL 12

Expert Comment

by:starlite551
ID: 35045820
If u need Auto Suggest option and Auto Complete in your ComboBox Control then you can add it using the following code :

For AutoComplete in All Urls that are present in the History..
 Try this one :
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.AllUrl;

Open in new window

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 16

Author Comment

by:Kalpesh Chhatrala
ID: 35045842
Thanks for reply.

i want to search in binded data table not from auto complete history

Second  thing i want to use combobox  in Desktop Application.
0
 
LVL 12

Expert Comment

by:starlite551
ID: 35052072
I have a method written in C# for you which returns the results of a search query in a DataSet Object then you can use the returned DataSet object to bind some other control like a DataGridView Control or use DataSet to display all the values of various rows in different TextBoxes So heres the method :

public DataSet GetSearchResults(string columnName,string tableName,string searchString,string connectionString)
{
      string cmd = "SELECT * FROM "+tableName+" WHERE "+columnName+" Like %"+searchString+"%";
      DataSet dsResult;
      using(SqlConnection cn = new SqlConnection(connectionString))
      {
            cn.Open();
            using(SqlCommand cm = new SqlCommand(cmd,cn))
            {
                 SqlDataAdapter da = new SqlDataAdapter(cm);
                 dsResult = new DataSet();
                 da.Fill(dsResult);                
            } 
      }   
      return dsResult;  
}

Open in new window


You have to use this method in the TextChanged Event of the ComboBox Control...
Like so..

 
DataSet dsSearchRec;
private void comboBox1_TextChanged(object sender, EventArgs e)
{
      dsSearchRec = GetSearchResults("Employee_Name","Employee","Jhon",@"Data Source=.\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=true;");
      dataGridView1.DataSource = dsSearchRec;
}

Open in new window

0
 
LVL 12

Expert Comment

by:starlite551
ID: 35052133
I am sorry I wrote hard coded value of "Jhon" as a searchString Parameter for the method in the TextChanged Event of the ComboBox.. Actually the code should have been this way :

DataSet dsSearchRec;
private void comboBox1_TextChanged(object sender, EventArgs e)
{
      dsSearchRec = GetSearchResults("Employee_Name","Employee",comboBox1.Text,@"Data Source=.\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=true;");
      dataGridView1.DataSource = dsSearchRec;
}

Open in new window


...In the place of "Jhon" I am using the value from comboBox1's Text property..
0
 
LVL 16

Author Comment

by:Kalpesh Chhatrala
ID: 35052792
each and every key press get data from data table it is not feasible.

any other solution ?
0
 
LVL 12

Expert Comment

by:starlite551
ID: 35064779
So you need data only when the key is pressed for the first time...??
0
 
LVL 16

Author Comment

by:Kalpesh Chhatrala
ID: 35065155
first time focus on combo all data will be displayed and there after user press key then the filtered result will be displayed..
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 35123642
Hi!

First step is to bind ComboBox with the column you want it to display:
        ComboBox1.DataSource = TestDataSet.tblA            
        ComboBox1.DisplayMember = "Text"                   ' A column "Text" of table "tblA" will be displayed.

You can use query to fill ComboBox as well.(as other experts suggested)

Now set two properties of ComboBox: (from Property window)
"AutoCompleteMode" to  "Suggest"
"AutoCompleteSource' to "ListItems"
0
 
LVL 16

Author Comment

by:Kalpesh Chhatrala
ID: 35170125
Hi Shahan_Developer,

Combobox Display seperate Suggested Item List

Not  Filter/Search in Dropdown List.
0
 
LVL 19

Accepted Solution

by:
Shahan Ayyub earned 250 total points
ID: 35171318
Hi!

On every key press the combo box extracts the items that best fits the current text of the combobox within its collection(contains all record from which we are going to filter). Is this not fulfill your requirement ???

It is equivalent to filter record(s) or search record(s) from collection.

BTW Dropdownlist is a web control while your question refers "ComboBox". there are some properties you will not find in dropdown list as in combobox.


0
 
LVL 16

Author Closing Comment

by:Kalpesh Chhatrala
ID: 35307623
..
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 35308865
Hi!

Why this multiplier ?? Is your problem not solved ??
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question