473,804 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fill a ComboBox

Hi everybody!

I got a combobox to fill.
I want to display some information (Text), but when I select a item, I want
to return a number.

The info I want to fill in is something like this:

TEXT VALUE
Category1 10
Category2 15
Category3 35

How can I perform this task?

Thanks!

Jul 21 '05 #1
8 1946
Hi,

Yes, one way would be to create a DataTable containing two columns for the
datasource and set DisplayMember and ValueMember accordingly:
DataTable table = new DataTable();

table.Columns.A dd("Id", typeof(int));

table.Columns.A dd("Description ", typeof(string)) ;

table.Rows.Add( new object[]{1, "One"});

table.Rows.Add( new object[]{2, "Two"});

comboBox1.Value Member = "Id";

comboBox1.Displ ayMember = "Descriptio n";

comboBox1.DataS ource = table;
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Pepehammer " <pe********@hot mail.com> wrote in message
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
Hi everybody!

I got a combobox to fill.
I want to display some information (Text), but when I select a item, I want to return a number.

The info I want to fill in is something like this:

TEXT VALUE
Category1 10
Category2 15
Category3 35

How can I perform this task?

Thanks!


Jul 21 '05 #2
A simple way is to create a class to hold your data. The combobox uses the
System.Windows. Forms.ComboBox. ObjectCollectio n class to hold the items for
the combobox and uses the ToString() method to get the text to display.
Simply create a class that has a String and an Integer and add a ToString()
method to return the String value.

See this previous newsgroup post...

http://groups.google.com/groups?q=vb...phx.gbl&rnum=1
"Pepehammer " <pe********@hot mail.com> wrote in message
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
Hi everybody!

I got a combobox to fill.
I want to display some information (Text), but when I select a item, I want to return a number.

The info I want to fill in is something like this:

TEXT VALUE
Category1 10
Category2 15
Category3 35

How can I perform this task?

Thanks!


Jul 21 '05 #3

How i fill the combobox with info from a database (SQL)?

Thanks
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:e1******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

Yes, one way would be to create a DataTable containing two columns for the
datasource and set DisplayMember and ValueMember accordingly:
DataTable table = new DataTable();

table.Columns.A dd("Id", typeof(int));

table.Columns.A dd("Description ", typeof(string)) ;

table.Rows.Add( new object[]{1, "One"});

table.Rows.Add( new object[]{2, "Two"});

comboBox1.Value Member = "Id";

comboBox1.Displ ayMember = "Descriptio n";

comboBox1.DataS ource = table;
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Pepehammer " <pe********@hot mail.com> wrote in message
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
Hi everybody!

I got a combobox to fill.
I want to display some information (Text), but when I select a item, I

want
to return a number.

The info I want to fill in is something like this:

TEXT VALUE
Category1 10
Category2 15
Category3 35

How can I perform this task?

Thanks!



Jul 21 '05 #4
This should give you what you need:

http://www.csharphelp.com/archives/archive151.html

MOOGY!

"Pepehammer " <pe********@hot mail.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .

How i fill the combobox with info from a database (SQL)?

Thanks
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:e1******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

Yes, one way would be to create a DataTable containing two columns for the datasource and set DisplayMember and ValueMember accordingly:
DataTable table = new DataTable();

table.Columns.A dd("Id", typeof(int));

table.Columns.A dd("Description ", typeof(string)) ;

table.Rows.Add( new object[]{1, "One"});

table.Rows.Add( new object[]{2, "Two"});

comboBox1.Value Member = "Id";

comboBox1.Displ ayMember = "Descriptio n";

comboBox1.DataS ource = table;
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Pepehammer " <pe********@hot mail.com> wrote in message
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
Hi everybody!

I got a combobox to fill.
I want to display some information (Text), but when I select a item, I

want
to return a number.

The info I want to fill in is something like this:

TEXT VALUE
Category1 10
Category2 15
Category3 35

How can I perform this task?

Thanks!




Jul 21 '05 #5
Hi,

You don't need database - you just use a class DataTable which is not linked
to database.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Pepehammer " <pe********@hot mail.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .

How i fill the combobox with info from a database (SQL)?

Thanks
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:e1******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

Yes, one way would be to create a DataTable containing two columns for the datasource and set DisplayMember and ValueMember accordingly:
DataTable table = new DataTable();

table.Columns.A dd("Id", typeof(int));

table.Columns.A dd("Description ", typeof(string)) ;

table.Rows.Add( new object[]{1, "One"});

table.Rows.Add( new object[]{2, "Two"});

comboBox1.Value Member = "Id";

comboBox1.Displ ayMember = "Descriptio n";

comboBox1.DataS ource = table;
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Pepehammer " <pe********@hot mail.com> wrote in message
news:OM******** ******@TK2MSFTN GP09.phx.gbl...
Hi everybody!

I got a combobox to fill.
I want to display some information (Text), but when I select a item, I

want
to return a number.

The info I want to fill in is something like this:

TEXT VALUE
Category1 10
Category2 15
Category3 35

How can I perform this task?

Thanks!




Jul 21 '05 #6
Hey Miha, did you see my post about how to receive event changes from the
SQL server?

Nobody has really responded. Would be nice to get some help on that...

MOOGY!
Jul 21 '05 #7
Hi Moogy,

William gave you a good answer.
If you want learn more on notification services, read online docs:
http://msdn.microsoft.com/library/?u...asp?frame=true

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Moogy" <no****@nospam. com> wrote in message
news:10******** *****@corp.supe rnews.com...
Hey Miha, did you see my post about how to receive event changes from the
SQL server?

Nobody has really responded. Would be nice to get some help on that...

MOOGY!

Jul 21 '05 #8
This seems a rather complex solution for enterprise-scale projects; my
client is a simple connection client for a small custom database, yet we may
have 3-4 people working on it at the same time.

Don't get me wrong, if this is the only way, I'll definitely have to pursue
it; I was just hoping that I could use triggers and an existing SQL
connection to communicate, or something along those lines.

I'm wondering if writing a RPC service may be the easier solution. I was
just hoping to use something internal to SQL...

There's no way to receive simple trigger messages through events that SQL
Server can raise through the connection?

MOOGY!

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:O4******** ******@TK2MSFTN GP09.phx.gbl...
Hi Moogy,

William gave you a good answer.
If you want learn more on notification services, read online docs:
http://msdn.microsoft.com/library/?u...asp?frame=true
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Moogy" <no****@nospam. com> wrote in message
news:10******** *****@corp.supe rnews.com...
Hey Miha, did you see my post about how to receive event changes from the SQL server?

Nobody has really responded. Would be nice to get some help on that...

MOOGY!


Jul 21 '05 #9

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

Similar topics

1
2376
by: Maurice Mertens | last post by:
Does anyone know how to get an auto-filling combobox on a form? When I add a combobox to a form I can set the DropDownStyle property to DropDownList. This will make the combobox auto-filling. But the user then can't enter text in the combobox which isn't in the list. So I have to set the DropDownStyle property to DropDown to enable the user to enter text which isn't in the list. But unfortunately the combobox doesn't auto-fill the text...
3
2125
by: Maurice Mertens | last post by:
Hi all, In VB.NET you can set the DropDownStyle for a combobox to 'DropDown' or 'DropDownList'. When you set it to DropDownList, it supports auto-fill. But when you set it to 'DropDown', the auto-fill support is gone. How can I get auto-fill on a combobox with a dropdownstyle 'DropDown'? --
2
1234
by: ken | last post by:
I would like to fill a combobox with the values of one column of the dataview I am using. When I set it up the way I expect it would be, I get every row in the combobox says: System.Data.DataRowView If I click on one, it navigates to the right place. Any idea how I would get the System.Data.DataRowView to show the actual values in the column? Thanks
7
8806
by: sparkle | last post by:
Hi Everybody, I'm filling a combobox from a class, which works fine on it's own. But when I insert code to fill in other controls something in the combobox fill is causing the SelectedIndexChanged event to happen when the form (hence combobox) loads, not when I select something from the combobox. Do I have something in the wrong order? I've read that that sometimes
6
7812
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows the item count correctly
9
379
by: Pepehammer | last post by:
Hi everybody! I got a combobox to fill. I want to display some information (Text), but when I select a item, I want to return a number. The info I want to fill in is something like this: TEXT VALUE Category1 10
5
22584
by: Tark Siala | last post by:
hi dear i'm programmer with VB6, but now i starting with C#. first problem is coming when i need fill "ComboBox Control", as you know when i fill combobox in VB6 by this code: comboX.AddItem "Monday" comboX.ItemData (comboX.NewIndex) = 1 comboX.text = ComboX.List(0) where:
2
2974
by: tshad | last post by:
In my VS 2003 Windows Forms page, when I initially fill my ComboBox (SystemList), it goes to the SelectedIndexChanged event which calls the Loademails() function. I then call it again in the Form1Load function. How do I get it not to call it in the SelectedIndexChanged from the Form1Load function? Normally, I want it to call it but not when I initally fill the ComboBox. *********************************************************...
1
1689
by: menyki | last post by:
am still finding it difficult as a new java user. am designing a software that has multiple forms, controls such as combobox and so on and finding it difficult to do the following. i want some combobox in the software to fill at design time, i.e. two combobox the first one already has 2 items, i want a situation whereby an item selected from the first combobox determines what items will fill the second combobox. secondly, i want to...
0
9705
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
9576
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
10074
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
9138
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
7613
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
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
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.