You should be able to get some ideas from this "sketch:"
using System;
namespace YourNameSpace
{
public class YourClass
{
private Tester TheTester;
private Opc.Server[] Servers;
private Opc.Da.Server CurrentServer;
private void ButtonGetListOfOPCServers_Click(object sender, EventArgs e)
{
TheTester = new Tester();
Servers = TheTester.Getserver();
if (Servers == null)
{
return;
}
else
{
ListBoxListOfOPCServers.DataSource = Servers;
ListBoxListOfOPCServers.DisplayMember = "Name";
ListBoxListOfOPCServers.SelectedIndexChanged += ListBoxListOfOPCServers_SelectedIndexChanged;
}
}
private void ListBoxListOfOPCServers_SelectedIndexChanged(object sender, EventArgs e)
{
int selNdx = ListBoxListOfOPCServers.SelectedIndex;
if (selNdx == -1)
{
return;
}
CurrentServer = ListBoxListOfOPCServers.SelectedValue as Opc.Da.Server;
if (CurrentServer == null)
{
return;
}
TheTester.M_server = CurrentServer;
}
}
}