473,563 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how i can fill combo box?

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.NewInde x) = 1
comboX.text = ComboX.List(0)

where:
Item is what Client can see.
ItemData what i want to know to make something (its like a key).

how i can do that with C# code?
thanks
-----------
Tarek M. Siala
Software Developer
http://tarksiala.blogspot.com
Jul 21 '07 #1
5 22568
"Tark Siala" <ta*******@ic c-libya.comwrote in message
news:eF******** ********@TK2MSF TNGP02.phx.gbl. ..
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.NewInde x) = 1
comboX.text = ComboX.List(0)

where:
Item is what Client can see.
ItemData what i want to know to make something (its like a key).

how i can do that with C# code?
thanks
-----------
Tarek M. Siala
Software Developer
http://tarksiala.blogspot.com

You need to learn about the Items collection of the ComboBox class.
This will help...

http://msdn2.microsoft.com/en-us/lib...ms(vs.80).aspx

Jul 21 '07 #2

"Tark Siala" <ta*******@ic c-libya.comwrote in message
news:eF******** ********@TK2MSF TNGP02.phx.gbl. ..
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.NewInde x) = 1
comboX.text = ComboX.List(0)

where:
Item is what Client can see.
ItemData what i want to know to make something (its like a key).
Create a class to hold your data, override ToString() to control what the
user sees:

class ListBoxEntry
{
public int ItemData;
public string Caption;

public ListBoxEntry(in t key, string text) { ItemData = key; Caption =
text; }
public override string ToString() { return Caption; }
}

comboX.Items.Ad d(new ListBoxEntry(1, "Monday"));
Jul 24 '07 #3
thanks

but how i can access to any "itemdata" or know what "itemdata" is selected
now in combobox?

for example: in VB6 i write this code:
Id = vba.trim(me.com bobox.itemdata( vba.abs(me.comb obox.listindex) ))
how i can read itemdata in C# like VB6 ?

thanks
-----------
Tarek M. Siala
Software Developer
http://tarksiala.blogspot.com

"Ben Voigt [C++ MVP]" <rb*@nospam.nos pamwrote in message
news:uU******** ******@TK2MSFTN GP04.phx.gbl...
>
"Tark Siala" <ta*******@ic c-libya.comwrote in message
news:eF******** ********@TK2MSF TNGP02.phx.gbl. ..
>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.AddIt em "Monday"
comboX.ItemDat a (comboX.NewInde x) = 1
comboX.text = ComboX.List(0)

where:
Item is what Client can see.
ItemData what i want to know to make something (its like a key).

Create a class to hold your data, override ToString() to control what the
user sees:

class ListBoxEntry
{
public int ItemData;
public string Caption;

public ListBoxEntry(in t key, string text) { ItemData = key; Caption =
text; }
public override string ToString() { return Caption; }
}

comboX.Items.Ad d(new ListBoxEntry(1, "Monday"));


Jul 25 '07 #4
On 25 Jul., 13:37, "Tark Siala" <tarksi...@ic c-libya.comwrote:
thanks

but how i can access to any "itemdata" or know what "itemdata" is selected
now in combobox?

for example: in VB6 i write this code:
Id = vba.trim(me.com bobox.itemdata( vba.abs(me.comb obox.listindex) ))
how i can read itemdata in C# like VB6 ?

thanks
-----------
Tarek M. Siala
Software Developerhttp://tarksiala.blogs pot.com

"Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote in messagenews:uU* *************@T K2MSFTNGP04.phx .gbl...
"Tark Siala" <tarksi...@ic c-libya.comwrote in message
news:eF******** ********@TK2MSF TNGP02.phx.gbl. ..
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.NewInde x) = 1
comboX.text = ComboX.List(0)
where:
Item is what Client can see.
ItemData what i want to know to make something (its like a key).
Create a class to hold your data, override ToString() to control what the
user sees:
class ListBoxEntry
{
public int ItemData;
public string Caption;
public ListBoxEntry(in t key, string text) { ItemData = key; Caption =
text; }
public override string ToString() { return Caption; }
}
comboX.Items.Ad d(new ListBoxEntry(1, "Monday"));
A combo/listbox doesn't have "itemdata" as in VB6, instead you can
access the combo-box's value/tag as an object of any datatype you
like.

1) create a windows application.
2) Add 1 combobox (named comboxBox1) , 1 button named button1 and 2
labels named label1 and label2.
3) Add this class to your form-class:

public class ComboBoxItem
{
private string _Caption = "No Caption Set";
private int _Value = 0;

public string Caption
{
get
{
return this._Caption;
}
set
{
this._Caption = value;
}
}
public int Value
{
get
{
return this._Value;
}
set
{
this._Value = value;
}
}
}

Add paste this code into the form-class's button1_click event (double
click on the button to get the event-code):
private void button1_Click(o bject sender, EventArgs e)
{
if (comboBox1.Sele ctedItem != null)
{
label1.Text = "Caption:" +
((ComboBoxItem) comboBox1.Selec tedItem).Captio n;
label2.Text = "Value:" +
((ComboBoxItem) comboBox1.Selec tedItem).Value. ToString();
}
}

and then this :

void LoadCombo()
{
// This can/should only be done once.
comboBox1.Displ ayMember = "Caption"; // Member from the ComboBoxItem
class to visualize.
// Using self-made class, for pupulation of the combobox.
// See ComboBoxItem (easy simple class)
ComboBoxItem CI;

CI = new ComboBoxItem();
CI.Caption = "My Caption";
CI.Value = 10;
comboBox1.Items .Add(CI); // Now the comboxbox item consists of a
ComboBoxItem (which can be any class).

CI = new ComboBoxItem();
CI.Caption = "My Caption2";
CI.Value = 20;
comboBox1.Items .Add(CI); // Now the comboxbox item consists of a
ComboBoxItem (which can be any class).
}

Now, add this to the form's load event:

private void Form1_Load(obje ct sender, EventArgs e)
{
LoadCombo();
}
That's it ! - You may design your ComboBoxItem class just as you need,
it can be anything, and the DisplayMember can even hold bitmaps for
visualizing icons etc. as far as i remember! - Try it out ! :-)

Regards
Brian Bergh
Jul 25 '07 #5

"Tark Siala" <ta*******@ic c-libya.comwrote in message
news:u0******** ******@TK2MSFTN GP05.phx.gbl...
thanks

but how i can access to any "itemdata" or know what "itemdata" is selected
now in combobox?

for example: in VB6 i write this code:
Id = vba.trim(me.com bobox.itemdata( vba.abs(me.comb obox.listindex) ))
how i can read itemdata in C# like VB6 ?
int Id = ((ListBoxEntry) (comboBox1.Sele ctedItem)).Item Data;
>
thanks
-----------
Tarek M. Siala
Software Developer
http://tarksiala.blogspot.com

"Ben Voigt [C++ MVP]" <rb*@nospam.nos pamwrote in message
news:uU******** ******@TK2MSFTN GP04.phx.gbl...
>>
"Tark Siala" <ta*******@ic c-libya.comwrote in message
news:eF******* *********@TK2MS FTNGP02.phx.gbl ...
>>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.AddIte m "Monday"
comboX.ItemDa ta (comboX.NewInde x) = 1
comboX.text = ComboX.List(0)

where:
Item is what Client can see.
ItemData what i want to know to make something (its like a key).

Create a class to hold your data, override ToString() to control what the
user sees:

class ListBoxEntry
{
public int ItemData;
public string Caption;

public ListBoxEntry(in t key, string text) { ItemData = key; Caption =
text; }
public override string ToString() { return Caption; }
}

comboX.Items.A dd(new ListBoxEntry(1, "Monday"));



Aug 2 '07 #6

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

Similar topics

4
6328
by: Eugene Anthony | last post by:
This is a table created in ms sql: create table categories ( CategoryID int IDENTITY, CategoryDescription varchar(30), ParentCategoryID int ); This is a stored procedure created in ms sql:
3
2198
by: Antoine Janssen | last post by:
hi, I would like to create two combo boxes. In the first one you can select a user in the second one you can select a project. To simplify the selection i would like to shorten the project list by just presenting the projects the selected user is working on (using a where clause with the userid filled in). Does onyone know how to achieve...
3
19400
by: Kannan | last post by:
hi Currently I am working in C# windows application. I am trying to fill combo box with values We have to always use datasource property for filling values in Combo box? In VB, normally i have used Item data property and display data property We can't use this similar method in C#?? please let me know. thankjs Kannan
2
1109
by: Jacques | last post by:
Hi , I've 24 Combo Box in a Group , connected to the same DataSource (ArrayList) : easy way to fill Combo . The pb i've , is that when i select an item in 1 combo then all other 23 will display the same entry , and of course i don't want that . Is there something quite simple that i could do force them , not to
2
6936
by: Jeremy Dillinger | last post by:
I have a program setup to pull data from a database. My database table has things such as (category, Item, price, etc.) In my program I want to have multiple list boxes that will have a pull down list of different categories. The category is stored as a number and the item is stored as a string. Also once the item is picked from the list I...
3
1493
by: Roger | last post by:
I want to fill a combo box with a Text value to show like name, but when it is selected I want to get the say SS# or Emp #. I will be filling this in manually how should I go about this. I know combo1.items.add(Item) But what I don't get is how to assign both the text and value at the same
1
7418
by: dthmtlgod | last post by:
I have a form on my webpage. There are many comboboxes. One of them is where a user can select a "State". Based on the state, I want to select a "County". The form should populate only the counties that apply to that State I know how to do the JOIN if needed, but not quite sure how to pass the value of the "State" combobox to the...
2
3263
by: ravindraredekar | last post by:
Hi, I am Using 2 combo i am filling 1st combo through data base value like company name. i want to fill the name of employee in second combo when i select company name from first combo can any body help me in this regards.
0
7580
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...
0
7882
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. ...
0
8103
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...
1
7634
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...
0
7945
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...
0
6244
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...
0
3634
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...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
916
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...

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.