Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 25th, 2007, 1:54 AM   #1
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
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.
Sil3ncer7 is offline   Reply With Quote
Old Sep 25th, 2007, 7:34 AM   #2
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
Quote:
Originally Posted by Sil3ncer7 View Post
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");
funny, it works for me. Double click on the form or select the load event from the properties window to make sure you're putting the above in the correct place.

Quote:
Originally Posted by Sil3ncer7 View Post
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
It should be:
if ((string)comboBox1.SelectedItem == "Multimedia")
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Sep 25th, 2007, 9:03 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 25th, 2007, 11:41 AM   #4
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
Quote:
Originally Posted by kruptof;134274
It should be:
[CODE
if ((string)comboBox1.SelectedItem == "Multimedia")[/code]
I tried this and it gives me a
Quote:
Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
and the applications dont show up in the lstApplication box
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards....
Sil3ncer7 is offline   Reply With Quote
Old Oct 4th, 2007, 12:40 AM   #5
Bharathi
Programmer
 
Join Date: Apr 2005
Posts: 32
Rep Power: 0 Bharathi is on a distinguished road
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
Bharathi is offline   Reply With Quote
Old Oct 4th, 2007, 8:06 PM   #6
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
Quote:
Originally Posted by Bharathi View Post
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");
}
}
}
}


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....
Sil3ncer7 is offline   Reply With Quote
Old Oct 5th, 2007, 1:39 AM   #7
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
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
Booooze is offline   Reply With Quote
Old Oct 6th, 2007, 2:46 PM   #8
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
Quote:
Originally Posted by Booooze View Post
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

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....
Sil3ncer7 is offline   Reply With Quote
Old Oct 17th, 2007, 2:05 PM   #9
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
Re: vb to c#... Need Help!!

Quote:
Originally Posted by Booooze View Post
if(comboBox1.SelectedText == "Multimedia"){
lstApplications.Items.Add("Item #1");
lstApplications.Items.Add("Item #2");
}
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....
Sil3ncer7 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC