Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class communication manager.in that i have this function.

C#
public void SetPortNameValues(object obj)
{
   foreach (string str in SerialPort.GetPortNames())
   {
      ((ComboBox)obj).Items.Add(str);
   }
}

In form1.cs[design] I have combobox1.

I want to call SetPortNameValues method i form1_load event.

can anyone help me?
Posted
Updated 20-Nov-13 0:41am
v2

Hi Bunty,

I don't know how in windows application,
but by using class then its common for all application so
just create an object for the class communication manager(used your naming convention).
like this in form1_load()
communication_manager commMgr = new communication_manager();//added underscore since i dont want to void the naming convention

and with that obj you can access the method like this
C#
commMgr.SetPortNameValues(object obj);

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v3
Firstly, add an event handler to the form Load event (easiest way to do this: Double Click on the Form in the design view)

This creates code which looks like that:

C#
public void form1_load(object sender, EventArgs e) {

}


In addition you need to create an instance of your communicationmanager and you need to add that call to the event:
C#
public void form1_load(object sender, EventArgs e) {
   var manager = new communicationmanager();
   manager.SetPortNameValues(combobox1);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900