Skip to content

How do I access a control within a static method? #123

@abcdef123ghi

Description

@abcdef123ghi

I need to show the message on a Datagridview,I tried the follwoing code,but it doesn't work

static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
       {
        // handle message received 
        string message = System.Text.Encoding.UTF8.GetString(e.Message);

        string guildstr = Guid.NewGuid().ToString();
        string topicstr = "/lists/thenumber";
        string clientstr = "client";
        string usernostr = "userno";
    
         
        int index = myform.MsgDGView.Rows.Add();
        myform.MsgDGView.Rows[index].Cells[0].Value = "1"; // Exception occured
        myform.MsgDGView.Rows[index].Cells[1].Value = guildstr;
        myform.MsgDGView.Rows[index].Cells[2].Value = topicstr;
        myform.MsgDGView.Rows[index].Cells[3].Value = clientstr;
        myform.MsgDGView.Rows[index].Cells[4].Value = usernostr;
        myform.MsgDGView.Rows[index].Cells[5].Value = message;
        myform.MsgDGView.Rows[index].Cells[6].Value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        for (int i = 0; i < myform.MsgDGView.RowCount; i++)
        {
            myform.MsgDGView.Rows[index].Cells[0].Value = (i + 1).ToString();
        }

        myform.MsgTextBox.Text = message;
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions