Link to home
Create AccountLog in
Avatar of rturney
rturneyFlag for United States of America

asked on

Attempting to create class for common mysql methods but can't create method that returns a combo box

I am learning C# and am struggling with classes.  I have a C# program that uses MySQL methods residing in Form1.  Another form, Form2, must share these methods.  I added a new class, MyClass, to hold these common methods.  I declare them as:

 public static string method1()  // because all the methods return a string value.

My problem is that in a few cases I have a method that needs to return a ComboBox or a ListBox.  I already did this when the method was in Form1, but when I tried to move it to MyClass and set it up as:

public static ComboBox method2()

the ComboBox is not available as a possible return type in the pulldown list (as you type).  Neither is ListBox or ArrayList.   Array is available but I'm not sure how to use it.  The ComboBox and ListBox return types were very convenient to return a list.  I could use ArrayList.  I haven't tried a string array because of the difficulty in declaring its size before knowing how many items will be returned.

The method is supposed to return a list of items that satisfy the given MySQL query.  


Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of rturney


Wow, that took care of that!  Thank you Fernando!

Will Form1 and Form2 be able to access the methods in MyClass by using:

comboBox1 = MyClass.method(...);

as long as method(...) is declared in MyClass as

public static ComboBox method(...)  ?

Avatar of rturney


Thank you very much for help Fernando!  Things seem hard now but help like yours is making the process smoother.  

Best regards,
In answer to your question, Yes.

Your welcome, glad I was of some help. ;=)