473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combo Box allow multiple characters

Currently, when the user presses a letter key the combo box will go to the
first item in the collection of the combo box starting with that letter. For
example user presses on "R", and "R2F" appears in the combo box, then the
user presses on "H", "HIF" appears.

I want the user to be able to enter 2 or 3 characters and the combo box will
step through as the user enters the letters. For example user presses on
"R", "R2F" appears, then the user presses "H", "RH" appears.

Nov 17 '05 #1
4 2343
Hi Mike,
I would inherit from the standard combo box and add the functionality like
in the code below:

using System;
//using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;

namespace WindowsApplicat ion2
{
class SearchableCombo Box : ComboBox
{
private string _searchString;

public SearchableCombo Box()
: base()
{
_searchString = "";
}

protected override void OnKeyPress(KeyP ressEventArgs e)
{
_searchString += e.KeyChar.ToStr ing();
this.SelectBest Match();
}

public void ResetSearchText ()
{
_searchString = "";
}

private void SelectBestMatch ()
{
for(int index=0; index<this.Item s.Count; index++)
{
string currentItem = (string)this.It ems[index];

if (currentItem.St artsWith(_searc hString))
{
this.SelectedIn dex = index;
return;
}
}
}
}
}
Hope that helps
Mark R Dawson
http://www.markdawson.org

"Mike L" wrote:
Currently, when the user presses a letter key the combo box will go to the
first item in the collection of the combo box starting with that letter. For
example user presses on "R", and "R2F" appears in the combo box, then the
user presses on "H", "HIF" appears.

I want the user to be able to enter 2 or 3 characters and the combo box will
step through as the user enters the letters. For example user presses on
"R", "R2F" appears, then the user presses "H", "RH" appears.

Nov 17 '05 #2
Hi Cadel,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need the ComboBox to search in the
collection automatically for the item you have typed, just as the IE
address bar does. If there is any misunderstandin g, please feel free to let
me know.

As far as I know, this is not supported by the .NET framework. IMO, you can
try to sub class the ComboBox and handle the KeyPress event to search
through the collection. There are a lot of people trying to do this. I
suggest you also search through google groups, and there might be solution.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #3
I copied your code in but no change in the combo box. I typed in "RH", show
"R2F", then I typed in "H", shows "HHH". I want to type in R then H and see
"RH".

I modifed
//private System.Windows. Forms.ComboBox cboPrivilege;
private SearchableCombo Box cboPrivilege;

also
//this.cboPrivile ge = new System.Windows. Forms.ComboBox( );
this.cboPrivile ge = new SearchableCombo Box();

I also debugged the code, stepping through I noticed _searchString does not
get cleared out when focus leaves combo box.

"Mark R. Dawson" wrote:
Hi Mike,
I would inherit from the standard combo box and add the functionality like
in the code below:

using System;
//using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;

namespace WindowsApplicat ion2
{
class SearchableCombo Box : ComboBox
{
private string _searchString;

public SearchableCombo Box()
: base()
{
_searchString = "";
}

protected override void OnKeyPress(KeyP ressEventArgs e)
{
_searchString += e.KeyChar.ToStr ing();
this.SelectBest Match();
}

public void ResetSearchText ()
{
_searchString = "";
}

private void SelectBestMatch ()
{
for(int index=0; index<this.Item s.Count; index++)
{
string currentItem = (string)this.It ems[index];

if (currentItem.St artsWith(_searc hString))
{
this.SelectedIn dex = index;
return;
}
}
}
}
}
Hope that helps
Mark R Dawson
http://www.markdawson.org

"Mike L" wrote:
Currently, when the user presses a letter key the combo box will go to the
first item in the collection of the combo box starting with that letter. For
example user presses on "R", and "R2F" appears in the combo box, then the
user presses on "H", "HIF" appears.

I want the user to be able to enter 2 or 3 characters and the combo box will
step through as the user enters the letters. For example user presses on
"R", "R2F" appears, then the user presses "H", "RH" appears.

Nov 17 '05 #4
Hi Mike L,
I did not automatically reset the text on lost focus, you will notice
there is a method called ResetSearchText , I just provided you with some
proof of concept code, the polishing is up to you :-)

I tried this code on my computer and it works fine, I am not sure why it
is not working for you, you need to like you did replace all ComboBox
references inside the System.Windows. Forms namespace with the new class, that
should be enough.
Mark R Dawson
http://www.markdawson.org

"Mike L" wrote:
I copied your code in but no change in the combo box. I typed in "RH", show
"R2F", then I typed in "H", shows "HHH". I want to type in R then H and see
"RH".

I modifed
//private System.Windows. Forms.ComboBox cboPrivilege;
private SearchableCombo Box cboPrivilege;

also
//this.cboPrivile ge = new System.Windows. Forms.ComboBox( );
this.cboPrivile ge = new SearchableCombo Box();

I also debugged the code, stepping through I noticed _searchString does not
get cleared out when focus leaves combo box.

"Mark R. Dawson" wrote:
Hi Mike,
I would inherit from the standard combo box and add the functionality like
in the code below:

using System;
//using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;

namespace WindowsApplicat ion2
{
class SearchableCombo Box : ComboBox
{
private string _searchString;

public SearchableCombo Box()
: base()
{
_searchString = "";
}

protected override void OnKeyPress(KeyP ressEventArgs e)
{
_searchString += e.KeyChar.ToStr ing();
this.SelectBest Match();
}

public void ResetSearchText ()
{
_searchString = "";
}

private void SelectBestMatch ()
{
for(int index=0; index<this.Item s.Count; index++)
{
string currentItem = (string)this.It ems[index];

if (currentItem.St artsWith(_searc hString))
{
this.SelectedIn dex = index;
return;
}
}
}
}
}
Hope that helps
Mark R Dawson
http://www.markdawson.org

"Mike L" wrote:
Currently, when the user presses a letter key the combo box will go to the
first item in the collection of the combo box starting with that letter. For
example user presses on "R", and "R2F" appears in the combo box, then the
user presses on "H", "HIF" appears.

I want the user to be able to enter 2 or 3 characters and the combo box will
step through as the user enters the letters. For example user presses on
"R", "R2F" appears, then the user presses "H", "RH" appears.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3807
by: Stephen Miller | last post by:
I have a page with many, dynamically generated combo boxes and I want to check all of them, before I add a unique value to specific combo. What would be the best way to work through the document and without needing to know the name of each combo box, check its value? Thanks, Stephen
1
2708
by: Robert Neville | last post by:
The solution to my dilemma seems straight-forward, yet my mind has not been forthcoming with a direct route. My Project form has a tab control with multiple sub-forms; these distinct sub-forms relate addresses (multiple addresses); companies, contacts, and tasks to each project (one to many). My challenge lies with the task sub-form which links to the Project form through ProjID. The task record links back to the respective master...
2
5450
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would like to eventually be able to filter down through the tables untill i can reach one unique record. I am creating a datbase to keep track of registered accounts for a stae program. Each account is registered into the program through a two...
2
1755
by: Inquiring_Mind | last post by:
i am creating a database. i have the following question.. as per the specs... i need to be able to pull other forms from the master form using either a list or a combo box. what is the difference between the two and the pros and cons how do i make each of them so that when i chose a name of a form it pulls it up with the information regarding that record (employee)
14
4960
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons for things like delete, save, edit, cancel buttons - in the footer, or on the form detail section? 2. If in the footer, how do you add them to the tab order?
2
1519
by: Kaz | last post by:
Hi, I have an Access 2002 database that is accessed by multiple users on a win 2003 server usually in a terminal services envronment. I have a couple of users who unexpectedly cannot know access records via combo boxes. The combo populates but the mouse cannot select a record with a click and neither can the arrow buttons or the enter key work. one user is in the administrator group so I would not think it is permissions related or is...
8
2664
by: banderson | last post by:
Hello, I have a combo box in which I want to display multiple fields by concatenating the fields together. If one of those concatenated fields is Null, then the combo box does not show anything. To rectify this I have created IIf statements to check if certain fields are Null and remove those fields from the concatenation. The problem I am having is how to check if multiple fields are Null. I think I need to use AND in my code, but cannot...
30
26496
ADezii
by: ADezii | last post by:
This week’s Tip of the Week will clearly demonstrate how you can dynamically set the Drop Down List Width of a Combo Box to the length of the longest item in its Row Source. The inspiration for this Tip came from one of our own resident Experts, mshmyob. In response to a Thread relating to this very Topic, mshmyob came up with a rather ingenious method to accomplish this task. He computed the Average Character Width of a String consisting of...
4
4114
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a corresponding Date Code which I then write to a table using VBA. When I try to enter a duplicate date code, it automatically finds the duplicate and will not allow me to add it again to that combo box. How do I configure that combo box so I can enter the...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.