Tuesday, 13 August 2013

c#: adding new item to comboBox

c#: adding new item to comboBox

I want list of clients with their ip address to be added to comboBox in
winforms but the list doesn't appear in comboBox.
Here is my code for server
// this my list of sockets for each client connected to server
list<Socket> astr = new list<socket>();
public Form1()
{
InitializeComponent();
addfg();
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
}
public void addfg()
{
foreach (Socket s in astr)
{
string str = string.Format("client : " + s.RemoteEndPoint);
comboBox1.Items.Add(new object[] {str})
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Items[0]);
}
But I am getting error "ArgumentException was unhandled"

No comments:

Post a Comment