Avatar of rturney
rturney
Flag 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.  

Thanks,
-Bob


.NET Programming

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rturney

ASKER
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(...)  ?

-Bob
rturney

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

Best regards,
-Bob
Fernando Soto

In answer to your question, Yes.

Your welcome, glad I was of some help. ;=)
Your help has saved me hundreds of hours of internet surfing.
fblack61