![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
vb to c#... Need Help!!
First off I am new at c#. Second, I am working on trying to remake my VB6 application in c#, well I have the form kinda laid out and I am having trouble filling in some stuff. here is a link to the vb application Here. When you first start the program, the list box (cboCatagory) has multimedia Internet, etc... When you click say Multimedia in cboCatagory the listbox (lstApplication) display the appropriate application that fits that profile say Media Player...
My problem is: In visual basic you put it in the "form Load", How do I display the items in cboCatagory? I have this down, but it doesnt load when the application starts... cboCatagory.Items.Add(""); cboCatagory.Items.Add("Multimedia"); cboCatagory.Items.Add("Word Processing"); cboCatagory.Items.Add("Internet"); cboCatagory.Items.Add("Web Design"); cboCatagory.Items.Add("Program Development"); Also say you click "Multimedia" how do you get the applications to show up in lstApplication? I have: if (cboCatagory = "Multimedia") then lstApplication=("Windows Media Player"); but that doesnt seem to work... Any ideas or pointers would be greatly appreciated.. -Thanks Last edited by Sil3ncer7; Sep 25th, 2007 at 2:11 AM. |
|
|
|
|
|
#2 | |||
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3
![]() |
Quote:
Quote:
if ((string)comboBox1.SelectedItem == "Multimedia")
__________________
Quote:
|
|||
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Also, read the "How to Post a Question" thread and learn how to use code tags (puts the code in a box to preserve indentation). See how nice Kruptof's code looks, compared to yours? If yours actually had indentation, it would look super ugly and unreadable without the tags.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 | ||
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Quote:
Quote:
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
||
|
|
|
|
|
#5 |
|
Programmer
Join Date: Apr 2005
Posts: 32
Rep Power: 0
![]() |
programming combo box in C#
Hi,
Your code worked for me. I have given full code for this exercise. Hope it helps. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace combotesting { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Add(""); comboBox1.Items.Add("Multimedia"); comboBox1.Items.Add("Word Processing"); comboBox1.Items.Add("Internet"); comboBox1.Items.Add("Web Design"); comboBox1.Items.Add("Program Development"); } private void button1_Click(object sender, EventArgs e) { if ((string)comboBox1.SelectedItem == "Multimedia") { MessageBox.Show("true"); } } } } Develop three-tier Database applications using C# and SQL server |
|
|
|
|
|
#6 | |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Quote:
Well kinda. If you select "multimedia" from the comboBox1, a listbox (lstApplication) should display text such as this: "Windows media player, iTunes, winamp,etc" I try this but it doesnt work: if cboBox1.items = "multimedia" Then lstApplication.Items.Add("Windows Media Player"); lstApplication.Items.Add("iTunes"); lstApplication.Items.Add("Winamp"); Am I even Close???
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
|
|
#7 |
|
Expert Programmer
|
Use the combobox1.Items.Add Method to add the items to the box under the form load event. If you want the list to be shown undre a press of the button, put it under button1_Click. If you want it to display when a item is selected or changed from the list box, put it under the SelectedIndexChanged Method. You can do that by double clicking the combo box. As for the code to display the correct list:
if(comboBox1.SelectedText == "Multimedia"){
ListBox1.Items.Add("Item #1");
ListBox1.Items.Add("Item #1");
}Put that code under the corresponding event (Index Changed or button press or whatever). Hope this helps ![]() |
|
|
|
|
|
#8 | |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Quote:
Ill try that and see what It'll do....
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Re: vb to c#... Need Help!!
I tried this in both the lstApplications root and the cboCatagory root and neither work
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB 2002 -> VB 2008 conversion | pal | Visual Basic .NET | 1 | Sep 15th, 2007 4:43 AM |