|
-
May 12th, 2004, 01:36 PM
#1
Thread Starter
Addicted Member
Add data to ComboBox [Resolved]
This is the problem. I can add data to a combobox if it is in the same class.
For example:
String x = "Test";
combobox1.Item.Add(x);
But if I have the data in another class I cannot add it.
For example
String x = "Test";
Form1 myForm = new Form1();
myForm.combobox1.Item.Add(x);
But it does not work. Any ideas? I am new to C#, so sorry if this is simple.
Last edited by jordan23; May 17th, 2004 at 08:20 AM.
-
May 12th, 2004, 02:15 PM
#2
Addicted Member
what error are you getting
-
May 12th, 2004, 02:36 PM
#3
Thread Starter
Addicted Member
I don't get an error, but it doesn't load the data to the combo box. I can't seem to get data from one class into a control in another.
-
May 12th, 2004, 03:23 PM
#4
Frenzied Member
From what I remember (having done something similar some time ago) what that is doing, is loading a new instance of the form and adding the item to the list on that new form. But you're not showing the form or making it visible so you wouldn't notice. You have to change a line in the class's constructor so that it saves the form that loaded it in a variable or something like that. I will have a look but there is something for you to look out for.
-
May 12th, 2004, 03:26 PM
#5
Thread Starter
Addicted Member
Thanks for the hint. Yeah, if you could give me an example that would be great. I understand in english what you are saying, but my C#(or lack of) terminology is pretty bad. Thanks again.
-
May 16th, 2004, 10:28 PM
#6
Lively Member
show it
Code:
string x="test";
Form2 f=new Form2();
f.comboBox1.Items.Add(x);
f.comboBox1.SelectedIndex=0;
f.Show();
provided that comboBox1 is public member on Form2. hope this helps. if not, sorry.
-
May 17th, 2004, 08:19 AM
#7
Thread Starter
Addicted Member
Thanks ayan. That does make sense. Your code worked perfectly. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|