Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Can't change controls from other class ?!

$
0
0

So I've made an event which execute some code that adds a item to a listview, but it doesn't add an item to a listview nor I can't change any other controls on the form like label etc..

But it does work with a messagebox, How strange is that...?

Piece of code from the form:

    public void OnConnect(Client client)
    {
        MessageBox.Show("this works");
        lvClients.Items.Add("this doesnt work");
    }
    public void OnDisconnect(Client client)
    {

    }

    private void listenToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Port port = new Port();
        if (port.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            Server server = new Server();
            server.connect += new Server.ClientConnected(OnConnect);
            server.disconnect += new Server.ClientDisconnected(OnDisconnect);
            server.ConnectionKey = "12344567";
            server.Port = int.Parse(port.txtPort.Text);
            server.MaxConnections = 1000;
            server.Listen();
        }
    }

piece of code from the other class (created events):

public delegate void ClientDisconnected(Client client);
        public event ClientDisconnected disconnect;

        public delegate void ClientConnected(Client client);
        public event ClientConnected connect;


        public int Port
        {
            get;
            set;
        }

        public int MaxConnections
        {
            get;
            set;
        }

        public string ConnectionKey
        {
            get;
            set;
        }

        public void CLIENTConnected(Client client)
        {

            connect(client);
        }

        public void CLIENTDisconnected(Client client)
        {
          
            
            disconnect(client);
        }

Hope you guys can help me out! Because this very frustrating, and also: it doesnt have anything to do with cross-threading, already tried invoking with delegates.

Thanks.




Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>