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

Home Posts Topics Members FAQ

.NET ComboBox Behavior Help

I'm working in .NET and I can't seem to get the behavior that I need
from the combobox. I'm sure it's possible, I just don't have the .NET
experience. Any help would be greatly appreciated. I need a combobox
with the following behavior:

- The user can type in any text they want
- When the user clicks the drop down button and selects an item from
the combobox the text for that item should be appended to the end of
the text already existing in the combo box.

For example: if the user types 'hello' into the combo box and then
clicks the drop down button and selects 'world', the control would then
append 'world' to the end of the existing 'hello' to end with 'hello
world'. I've tried overriding OnSelectionChan geCommitted,
OnSelectedValue Changed, OnSelectedItemC hanged, and
OnSelectedIndex Changed, but to no avail. When I modify the .Text
property of the combobox while inside any of those events it does not
appear to change (I can force the change by refreshing the control with
Invalidate() or Refresh()), but once it exists the event, the .Text
property is then overwritten with the text that the user clicked from
the drop down. I'm sure this all sounds crazy easy, but I just can't
get it. Once again, I appreciate everyone's help. Hope you all had a
happy holiday season.

Respectfully,
Brian Hasden

Jul 21 '05 #1
5 2203
Hi Brian,

It's certainly an odd ComboBox and one that might be easier to create
using a separate TextBox for the user typing.

The problem is that once you select anything the selected value that is
drawn is whatever is on the SelectedIndex position of the Items property.
To override any ComboBox editbox feature you need to specify DrawMode to
either of the OwnerDrawn ones. However, you can't draw inside the editbox
unless you also specify DropDownList as the DropDownStyle, which
eliminated easy user typing.

This ComboBox will let you append selected words to whatever text is
already written inside the editbox, but won't let you type anything of
your own. Note however that using the up/down arrow keys each item in
turn will be selected and appended, and there is no undo option.

When you do ownerdrawn comboboxes you are responsible to draw selection
backgrounds and highlights or the ComboBox might look odd.

public class MyCombo : ComboBox
{
// this holds what you be shown in the editbox
private string tex = "";

// this method will be called once for each item in the dropdown list
// as well as the editbox if dropdownlist is specified
protected override void OnDrawItem(Draw ItemEventArgs e)
{
if (e.Index == -1)
return;
SolidBrush front;
SolidBrush back;

// determine front and back brush based on selected status
if ((e.State & DrawItemState.S elected) > 0)
{
front = new SolidBrush(Syst emColors.Highli ghtText);
back = new SolidBrush(Syst emColors.Highli ght);
}
else
{
front = new SolidBrush(this .ForeColor);
back = new SolidBrush(this .BackColor);
}

// if we are drawing the editbox use the appended text
string s = (e.State & DrawItemState.C omboBoxEdit) > 0 ? this.tex :
this.Items[e.Index].ToString();
e.Graphics.Fill Rectangle(back, e.Bounds);
e.Graphics.Draw String(s, this.Font, front, e.Bounds);

back.Dispose();
front.Dispose() ;
}

// each selection is appended to previously selected text
protected override void OnSelectionChan geCommitted(Eve ntArgs e)
{
if (this.SelectedI ndex > -1)
this.tex += this.Items[this.SelectedIn dex];
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2
Well that's not exactly what I was looking for but thanks anyways. One
more question real quick if you don't mind. What is the problem with
having a variable to hold what the combo box should be displaying and
polling to make sure that the combobox equals that variable? I know
polling isn't the best idea, but it would create the functionality that
I really need.

Jul 21 '05 #3
On 30 Dec 2004 18:04:35 -0800, hasden <bh*****@alltel .net> wrote:
Well that's not exactly what I was looking for but thanks anyways. One
more question real quick if you don't mind. What is the problem with
having a variable to hold what the combo box should be displaying and
polling to make sure that the combobox equals that variable? I know
polling isn't the best idea, but it would create the functionality that
I really need.


No problem, and may even be the best solution for what you want to do.
All my samples end up with the Text property of the ComboBox being
updated after any of the events I have tried effectively overruling any
manual changes. You could activate a timer in the event and set the
Text property when the timer sets in.
--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #4
Yeah that's exactly what happened to me. I couldn't trap any event that
let me have final say over what the Text property ended up with. Thank
you for all your help. I really just needed confirmation that I wasn't
going crazy and couldn't find/handle the events correctly. Thanks again.

Jul 21 '05 #5
We have a similar situation (in a .NET, C# application). We have an
application with a few drop downs that have a few thousand items. The
..NET combo box lets the user type in the first letter to narrow the list
down...however, with a very long list, the user still has to scroll a
good bit to get to the item they are looking for. Obviously, this is
tedious and undesirable.

Anyone has any ideas, how we could give our users the desired
functionality?

Thank you.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #6

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

Similar topics

0
2055
by: jean | last post by:
hi: i am developing a custom combobox for my company's needs that is made up of a textbox, listbox, button. i am using c#. everything is fine except for one issue. in a normal combobox, when the dropdown is visible and the user clicks anywhere else, the dropdown gets hidden. i am trying to replicate this behavior and have tried using the Leave and LostFocus events. i have had marginal success when my dropdown is visible and i...
5
3061
by: Steve | last post by:
I have an unbound combobox in the form header of a continuous form. The selection in the combobox sets the where clause in a querydef which determines QryPFrmInventoryManagement. The following code is in the afterupdate event of the combobox: Me.RecordSource = "QryPFrmInventoryManagement" Me!ItemCount = Me.RecordsetClone.RecordCount & " Items" MsgBox Me.RecordsetClone.RecordCount & " Items"
7
20763
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well. The control populates well, both the display values, and selected values. However, when i try to "set" the SelectedValue or SelectedIndex properties, nothing happens.... The default blank value in the ComboBox is always selected. My code is: ...
9
4142
by: Strahimir Antoljak | last post by:
Could anyone help me with the following: Is there a quick, or at least known way to force a ComboBox, having DropDownStyle= DropDownList, to recognize keyboard input and perform Item selection based on that. To be more specific: I have a list of 150 items (all 7-digit numeric values) represented in the combobox, and they are sorted. Instead
4
2608
by: Strahimir Antoljak | last post by:
Has anyone experienced problems with a combo box SelectIndex property? Is there a limit to the number of Items for a combo box? Namely, when I set programmatically ComboBox.SelectIndex property with 2000 Items listed in the ComboBox, SelectIndex property accepts assigned value. However, when I try to use SelectIndex
5
2147
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i drop down the combo box as the users typing. When the on leave event is fired the value in the selected
0
407
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
5
342
by: hasden | last post by:
I'm working in .NET and I can't seem to get the behavior that I need from the combobox. I'm sure it's possible, I just don't have the .NET experience. Any help would be greatly appreciated. I need a combobox with the following behavior: - The user can type in any text they want - When the user clicks the drop down button and selects an item from the combobox the text for that item should be appended to the end of the text already...
6
2873
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
0
8395
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...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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
7330
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
6166
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
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
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
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.