Open Form Via Contexmenustrip, random value click event

Asked

Viewed 57 times

1

I have the following problem:

I have 2 form FrmCadastroPessoa and FrmCadEscala.

In FrmCadastroPessoa have the DataGridView shown, when I right click on a Cell, lists the scales the person is registered to.

But these scale lists are generated at runtime, at each click of mouse, i clean (.Clear()) the ContexMenuStrip and add the scales that came from Select.

What can I call the FrmCadEscala and pass the ID of the person to his builder?

The question is, how will I generate the event Click(of ContexMenuStrip) of something I don’t know the name or how many will have?

inserir a descrição da imagem aqui

public frmCadEscala()
{
    InitializeComponent();
    Atualizar();
}

public frmCadEscala(int id)
{
    InitializeComponent();
    Atualizar(id);
}

Event code click on Datagridview

 
private void dgvPessoa_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if(e.RowIndex == -1)
            {
                return;
            }
            cmsListarEscala.Items.Clear();
            if (e.Button == MouseButtons.Right)

{ // para não precisar fazer outro select, coloquei se a imagem for cancel(não tem escala) então não exibe if (dgvPessoa.Rows[dgvPessoa.CurrentRow.Index].Cells["ESCALA"].Value == global::Row.Properties.Resources.Cancel_32x32) { return; } else { int n = e.RowIndex; int m = dgvPessoa.Rows[e.RowIndex.toInt32()].Cells["ID"].Value.toInt32(); DataTable DTE = this.e.BuscarTodasEscalasPessoa(dgvPessoa.Rows[e.RowIndex.toInt32()].Cells["ID"].Value.toInt32()); if (DTE != null) { for (int i = 0; i < DTE.Rows.Count; i++)// coloco as escalas no CMSListarEscala { cmsListarEscala.Items.Add(DTE.Rows[i]["ESCALA"].ToString()); } cmsListarEscala.Show(MousePosition); // exibo } } } else { return; }

  • Please post the code in text instead of images.

  • The idea will be to click, for example, on the option 3 VENDA and open the FrmCadEscala with the selected line ID?

  • João Martins, Yes. But have a problem the '3 sale' is a scale of the line clicked, I add it at runtime, as I will generate the event click her, Being that it is generated according to each person?

  • That line int m = dgvPessoa.Rows[e.RowIndex.toInt32()].Cells["ID"].Value.toInt32(); does not put in m the ID you want to pass to the form construct frmCadEscala?

  • 1

    Yes, I got it, I found that I can use the CMS Click method and filter the name of the selected item, so I pass the Item Name to the constructor, search by the name id and open the Frmcadescala the way I wanted, I used it just to see if the same kkk ID was coming, where do I close the question?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.