473,782 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to multiselect entries in drop down

I need to select multiple entries in the drop down list.

E.g. Search a string in languages like C#, VB, Java etc. These entries
are in drop down. So i need to multi select to search in multiple
languages

1. One of the option could be to have a check box beside each entry in
drop down. Do any one have an idea how to do this. Solution in C# is
required but even if its unmanaged code is OK.

2. Do any one have another idea for this multi select problem.

Jan 11 '07 #1
5 12253
Ajith, my understanding is that the dropdown is designed for single
selections.

You would be better off using a listview. This allows for multiple
selections, you could then return the selecteditems array to find out
which options were selected.

If it's the dropdown style look and feel your after, you can make sure
that the column headers aren't displayed by ensuring the listview isn't
set to detailed view. You can then play around with the events to hide
and display the listview so that it behaves in a similar way to a
dropdown box.

hth,

Gary.
Ajith Menon wrote:
I need to select multiple entries in the drop down list.

E.g. Search a string in languages like C#, VB, Java etc. These entries
are in drop down. So i need to multi select to search in multiple
languages

1. One of the option could be to have a check box beside each entry in
drop down. Do any one have an idea how to do this. Solution in C# is
required but even if its unmanaged code is OK.

2. Do any one have another idea for this multi select problem.
Jan 11 '07 #2
Hi,

You need to implement ownerdrawing of the items, which means setting
DropDownStyle to DropDownList, and DrawMode to OwnerDrawFixed. Then you
need to implement the DrawItem event and code similar to the below

private void comboBox1_DrawI tem(object sender, DrawItemEventAr gs e)
{
e.DrawBackgroun d();

if ((e.State & DrawItemState.C omboBoxEdit) 0)
{
e.Graphics.Draw String("One, Two", comboBox1.Font,
SystemBrushes.C ontrolText, e.Bounds.Left, e.Bounds.Top);
}
else if (e.Index -1)
{
if (comboBox1.Item s[e.Index].ToString() == "Two")
e.Graphics.Draw String("V", comboBox1.Font,
Brushes.Green, e.Bounds.Left, e.Bounds.Top);

e.Graphics.Draw String(comboBox 1.Items[e.Index].ToString(),
comboBox1.Font, SystemBrushes.C ontrolText, e.Bounds.Left + 20,
e.Bounds.Top);
}
}

This will draw "One, Two" in the EditBox if DrawItemEventAr gs.State
contains DrawItemState.C omboBoxEdit. Replace "One, Two" with some method
calculating which language is selected.

For the rest of the items it will simply draw the item name, with the
names pushed right 20 pixels, and draw a V in front of "Two" indicating
that "Two" is selected. Instead of using DrawString to draw a V, use
DrawImage with an image of a check mark.

e.DrawBackgroun d() takes care if the selected background color, but to
highlight the text of the selected line, use e.State to determine when
this should occur. Tip, use DrawItemState.F ocus and
SystemBrushes.H ighlightText

On Thu, 11 Jan 2007 11:38:46 +0100, Ajith Menon <ko********@gma il.com
wrote:
I need to select multiple entries in the drop down list.

E.g. Search a string in languages like C#, VB, Java etc. These entries
are in drop down. So i need to multi select to search in multiple
languages

1. One of the option could be to have a check box beside each entry in
drop down. Do any one have an idea how to do this. Solution in C# is
required but even if its unmanaged code is OK.

2. Do any one have another idea for this multi select problem.


--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 11 '07 #3
Thanks Morten ..... thanks a lot :)

I have never got a solution to any problem so fast after posting to the
Google groups or any other forums.
What a superb solution and exactly what I needed.

Now i am just trying to fit in the image exactly at the place required.
I notice that when I move the mouse over the entry it gets refreshed
and the image goes away.
But thats not a big deal ... i know i will find a solution to that.

Morten Rocks!!!
And Gary thanks for your suggestion, but the requirement is such that a
listbox won't do.
And as far as the code given by Morten is concerned, just add an entry
with name "Two" and you will see the "V" besides that. This is just an
example, you can make your own rules to make the check visible and
invisible.

Regards,
Ajith
Morten Wennevik [C# MVP] wrote:
Hi,

You need to implement ownerdrawing of the items, which means setting
DropDownStyle to DropDownList, and DrawMode to OwnerDrawFixed. Then you
need to implement the DrawItem event and code similar to the below
Jan 11 '07 #4
Hi i was very interested in this. Could you explain it a bit easier
please. I tried to do this. And when I run my form the combo box
displays one,two as you said.

But if i add items to the collection using the ide, and then run it
again and click on items they dont receive a v in front of them.

Have i misunderstood this?

Please elaborate,

Thanks,

gary.
Morten Wennevik [C# MVP] wrote:
Hi,

You need to implement ownerdrawing of the items, which means setting
DropDownStyle to DropDownList, and DrawMode to OwnerDrawFixed. Then you
need to implement the DrawItem event and code similar to the below

private void comboBox1_DrawI tem(object sender, DrawItemEventAr gs e)
{
e.DrawBackgroun d();

if ((e.State & DrawItemState.C omboBoxEdit) 0)
{
e.Graphics.Draw String("One, Two", comboBox1.Font,
SystemBrushes.C ontrolText, e.Bounds.Left, e.Bounds.Top);
}
else if (e.Index -1)
{
if (comboBox1.Item s[e.Index].ToString() == "Two")
e.Graphics.Draw String("V", comboBox1.Font,
Brushes.Green, e.Bounds.Left, e.Bounds.Top);

e.Graphics.Draw String(comboBox 1.Items[e.Index].ToString(),
comboBox1.Font, SystemBrushes.C ontrolText, e.Bounds.Left + 20,
e.Bounds.Top);
}
}

This will draw "One, Two" in the EditBox if DrawItemEventAr gs.State
contains DrawItemState.C omboBoxEdit. Replace "One, Two" with some method
calculating which language is selected.

For the rest of the items it will simply draw the item name, with the
names pushed right 20 pixels, and draw a V in front of "Two" indicating
that "Two" is selected. Instead of using DrawString to draw a V, use
DrawImage with an image of a check mark.

e.DrawBackgroun d() takes care if the selected background color, but to
highlight the text of the selected line, use e.State to determine when
this should occur. Tip, use DrawItemState.F ocus and
SystemBrushes.H ighlightText

On Thu, 11 Jan 2007 11:38:46 +0100, Ajith Menon <ko********@gma il.com>
wrote:
I need to select multiple entries in the drop down list.

E.g. Search a string in languages like C#, VB, Java etc. These entries
are in drop down. So i need to multi select to search in multiple
languages

1. One of the option could be to have a check box beside each entry in
drop down. Do any one have an idea how to do this. Solution in C# is
required but even if its unmanaged code is OK.

2. Do any one have another idea for this multi select problem.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 11 '07 #5
Hi Gary,

As Ajith said, I just added the simplest logic possible and to determine
if a V should be drawn I just checked to see if the name of the item ==
"Two".

To implement a multichecked combobox you will need to store the selected
items somewhere, like a List.

if (comboBox1.Item s[e.Index].ToString() == "Two")
e.Graphics.Draw String("V", comboBox1.Font, Brushes.Green, e.Bounds.Left,
e.Bounds.Top);

will then change to something like

if(MyList.Conta ins(comboBox1.I tems[e.Index])
e.Graphics.Draw String("V", comboBox1.Font, Brushes.Green, e.Bounds.Left,
e.Bounds.Top);

You will also have to subscribe to SelectedIndexCh anged event to keep
track of which items should be in MyList. Add the selected item, or if
the selected item is already in the list, remove it.

The drawing of "One, Two" should be replaced with something like this

string s = "";
foreach(string item in MyList)
{
s += item + ", ";
}
On Thu, 11 Jan 2007 15:23:30 +0100, Gary <ga********@myw ay.comwrote:
Hi i was very interested in this. Could you explain it a bit easier
please. I tried to do this. And when I run my form the combo box
displays one,two as you said.

But if i add items to the collection using the ide, and then run it
again and click on items they dont receive a v in front of them.

Have i misunderstood this?

Please elaborate,

Thanks,

gary.
Morten Wennevik [C# MVP] wrote:
>Hi,

You need to implement ownerdrawing of the items, which means setting
DropDownStyl e to DropDownList, and DrawMode to OwnerDrawFixed. Then you
need to implement the DrawItem event and code similar to the below

private void comboBox1_DrawI tem(object sender,
DrawItemEventA rgs e)
{
e.DrawBackgroun d();

if ((e.State & DrawItemState.C omboBoxEdit) 0)
{
e.Graphics.Draw String("One, Two", comboBox1.Font,
SystemBrushes. ControlText, e.Bounds.Left, e.Bounds.Top);
}
else if (e.Index -1)
{
if (comboBox1.Item s[e.Index].ToString() == "Two")
e.Graphics.Draw String("V", comboBox1.Font,
Brushes.Gree n, e.Bounds.Left, e.Bounds.Top);

e.Graphics.Draw String(comboBox 1.Items[e.Index].ToString(),
comboBox1.Font , SystemBrushes.C ontrolText, e.Bounds.Left + 20,
e.Bounds.Top );
}
}

This will draw "One, Two" in the EditBox if DrawItemEventAr gs.State
contains DrawItemState.C omboBoxEdit. Replace "One, Two" with some
method
calculating which language is selected.

For the rest of the items it will simply draw the item name, with the
names pushed right 20 pixels, and draw a V in front of "Two" indicating
that "Two" is selected. Instead of using DrawString to draw a V, use
DrawImage with an image of a check mark.

e.DrawBackgrou nd() takes care if the selected background color, but to
highlight the text of the selected line, use e.State to determine when
this should occur. Tip, use DrawItemState.F ocus and
SystemBrushes. HighlightText

On Thu, 11 Jan 2007 11:38:46 +0100, Ajith Menon <ko********@gma il.com>
wrote:
I need to select multiple entries in the drop down list.

E.g. Search a string in languages like C#, VB, Java etc. These entries
are in drop down. So i need to multi select to search in multiple
languages

1. One of the option could be to have a check box beside each entryin
drop down. Do any one have an idea how to do this. Solution in C# is
required but even if its unmanaged code is OK.

2. Do any one have another idea for this multi select problem.

--
Happy Coding!
Morten Wennevik [C# MVP]


--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 12 '07 #6

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

Similar topics

1
5026
by: Danny | last post by:
I like the combo box because you can scroll through items nicely, but the list box just has the navigation where you can go up and down. I am trying to allow the user to multiselect items. With the list box, he does not like it because if he clicks on the nav bar, it loses the selection!! even if he holds down the shift. Is there a way to do this with a combo box? I just see the multi select for the list box. Thanks in advance
4
5344
by: Abbey Krystowiak | last post by:
Does anyone know if I can have a field in a row where I can add two lines of info without adding a whole new line? and then there would be a drop down menu? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
6162
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box that appear when user clicks the drop-down arrow button. Because items in the Drop down list are a little long, user can't see the full thing when they pull down the items from the drop down list.
0
296
by: Robert | last post by:
Hi, I have a program with a ListView (with Multiselect) and am using the SelectedIndexChanged handler. However, when the index is changed, a rather long set of events occurs which takes quite some time. Therefore, if the user tries to multiselect several items (holding down Shift), it takes that many times longer. Is there a way to only invoke the SelectedIndexChanged method on the LAST multiselected item (not each and every one)?? ...
2
1954
by: Steph | last post by:
I have created a multiselect list box control (lbx_comorb) that is populated from a datatable (dt_ptAdmission). The list box populates now problem at all. However the issue is when I load the webform, when there is already admission data. I need the populated list box (lbx_comorb) to show the items that were previously selected for this admission. The selected comorb data is stored in another datatable (dt_ptComorb). If anyone can...
1
2323
by: gimme_this_gimme_that | last post by:
What I need is the DHTML for an input box that allows javascript to add drop down entries. .... I'd like to create my own version of google suggest GS. If you haven't seen GS check it out at : http://www.google.com/webhp?complete=1&hl=en
2
1600
by: ttime | last post by:
I've got a form that uses a multiselect listbox. When a user is selected from a combo box, values are populated into this listbox associated with that user. The problem is, if one person has say 10 entries in the listbox, and selects the last 3-4, and the next user only has 2 entries, those last 3-4 rows are still highlighted in the listbox. This introduces null values into my code which is definitely not good. I've tried using...
1
1717
by: ksex948 | last post by:
Hi, I am working with two listboxes that are initially getting populated from database tables (Access). They basically allow the user to transfer information back and forth from one listbox to the other listbox WITHOUT affecting the database. My question is this. When the user selects <Save Changes>, I want to be able to update the database table with the information in Listbox1. Basically like a security setup utility. What's my...
5
2672
by: atlanteavila | last post by:
Hello all, I've attached a database here that we're using to register people for a series of classes, for a course that we're offering for pre-baptismal certification. I'm wondering if there is a way that we could use one selection from the drop down list to auto populate the entire course dates in the sub form. That way, we would only select one item instead of having to select every class individually for every person that registers. ...
0
9641
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
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
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
9944
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
8968
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...
0
6735
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
2
3643
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.