473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1906
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.Add("Id", typeof(int));

table.Columns.Add("Description", typeof(string));

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

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

comboBox1.ValueMember = "Id";

comboBox1.DisplayMember = "Description";

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

"Pepehammer" <pe********@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP09.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.ObjectCollection 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********@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP09.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**************@TK2MSFTNGP11.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.Add("Id", typeof(int));

table.Columns.Add("Description", typeof(string));

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

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

comboBox1.ValueMember = "Id";

comboBox1.DisplayMember = "Description";

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

"Pepehammer" <pe********@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP09.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********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.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**************@TK2MSFTNGP11.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.Add("Id", typeof(int));

table.Columns.Add("Description", typeof(string));

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

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

comboBox1.ValueMember = "Id";

comboBox1.DisplayMember = "Description";

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

"Pepehammer" <pe********@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP09.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********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.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**************@TK2MSFTNGP11.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.Add("Id", typeof(int));

table.Columns.Add("Description", typeof(string));

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

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

comboBox1.ValueMember = "Id";

comboBox1.DisplayMember = "Description";

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

"Pepehammer" <pe********@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP09.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.supernews.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**************@TK2MSFTNGP09.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.supernews.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
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...
3
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...
2
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: ...
7
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...
6
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...
9
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: ...
5
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...
2
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.