Inquiridor
Problema clique ContextMenuStrip

Pergunta
-
Pessoal Boa Tarde,
Estou com um problema a vários e vários dias e não acho absolutamente nada na internet e nem no projeto.
E assim, eu tenho vários datagrids em um projeto e em 90% deles foi adicionado um ContextMenuStrip, quando ele clica com o botão direito do mouse em cima de um registro aparere as opções deletar e editar, so que em TODOS os datagrids com contextmenustrip do projeto quando eu clico em cima do grid com o botão direito para abrir as opções ele chama um form q seria o inicio do software após o login, isso acontece so na primeira vez q eu clico na segunda em diante ele já mostra o menu sem problemas.
Alguns testes que fiz no projeto foi que nestes forms q estão acontecendo isso se eu tirar o contextmenustrip do datagrid e clica sobre o datagrid num acontece nada, quando eu vo la nas propriedades do grid e coloco o contextmenustrip d novo o problema volta. Já procurei em todo o código e não existe nada chamando clique do botão. A baixo todo o código de um dos Forms com problema
Public Class AddFamiliaFRM #Region "Variáveis" Private recebeAI As Integer Private linha As Integer Private idFamiliar As Integer Private objBLL As BLL.AddFamiliaBLL #End Region #Region "Construtores" Public Sub New(ByVal vAI As Integer) ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. recebeAI = vAI End Sub #End Region #Region "Funções do formulario" 'Limpar campos texto do form Private Sub limpaForm() txtNome.Text = "" txtParentesco.Text = "" txtProfissao.Text = "" mtbNascimento.Text = "" End Sub Private Function validaData(ByVal valor As String) Dim dt As DateTime DateTime.TryParseExact(valor, "dd/MM/yyyy", Nothing, Nothing, dt) Return dt End Function Private Sub carregaGrid() Try 'Preenche Grid objBLL = New BLL.AddFamiliaBLL dgFamiliares.DataSource = Nothing dgFamiliares.DataSource = objBLL.preencheGridFamiliares(recebeAI, cbFamilia.SelectedValue) dgFamiliares.Columns(0).Visible = False dgFamiliares.Columns(1).Width = 200 dgFamiliares.BackgroundColor = Color.WhiteSmoke dgFamiliares.BorderStyle = BorderStyle.None dgFamiliares.ReadOnly = True Catch ex As Exception MessageBox.Show(ex.Message) Finally objBLL = Nothing End Try End Sub Private Sub habilita(ByVal valor As Boolean) If (valor = False) Then Label7.Visible = False gbPessoa.Enabled = False Label8.Visible = True txtNomeFamilia.Visible = True btFamilia.Visible = True btFamiliaCancela.Visible = True cbFamilia.Enabled = False btAdicionar.Enabled = False dgFamiliares.Visible = False Else Label7.Visible = True gbPessoa.Enabled = True Label8.Visible = False txtNomeFamilia.Visible = False btFamilia.Visible = False btFamiliaCancela.Visible = False cbFamilia.Enabled = True btAdicionar.Enabled = True dgFamiliares.Visible = True End If End Sub Private Sub preencherCombo() Dim objDAO As New DAO.ConexaoBD objDAO.preencheCombo(cbFamilia, "SELECT id_familia,nome_familia FROM familia WHERE id_acolhe=" & recebeAI, "nome_familia", "id_familia") objDAO = Nothing End Sub #End Region #Region "Ações" #Region "Load" Private Sub AddFamiliaFRM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try 'Preenche combobox preencherCombo() carregaGrid() 'Esconde controles para adicionar familia Label8.Visible = False txtNomeFamilia.Visible = False btFamilia.Visible = False btFamiliaCancela.Visible = False Catch ex As Exception MessageBox.Show(ex.Message) Finally objBLL = Nothing End Try End Sub #End Region #Region "Clique do botão adicionar" Private Sub btAdicionar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAdicionar.Click Try If idFamiliar = 0 And txtNome.Text <> "" And txtParentesco.Text <> "" And txtProfissao.Text <> "" And validaData(mtbNascimento.Text) <> DateTime.MinValue Then objBLL = New BLL.AddFamiliaBLL objBLL.insereFamiliar(recebeAI, txtNome.Text, txtParentesco.Text, mtbNascimento.Text, txtProfissao.Text, cbFamilia.SelectedValue) carregaGrid() limpaForm() txtNome.Focus() ElseIf idFamiliar <> 0 And txtNome.Text <> "" And txtParentesco.Text <> "" And txtProfissao.Text <> "" And validaData(mtbNascimento.Text) <> DateTime.MinValue Then objBLL = New BLL.AddFamiliaBLL objBLL.atualizaFamiliar(idFamiliar, txtNome.Text, txtParentesco.Text, mtbNascimento.Text, txtProfissao.Text, cbFamilia.SelectedValue) idFamiliar = 0 btAdicionar.Text = "Adicionar" carregaGrid() limpaForm() cmsFamilia.Enabled = True Else MessageBox.Show("Preencha todos os campos corretamente.") End If Catch ex As Exception MessageBox.Show(ex.Message) Finally objBLL = Nothing End Try End Sub #End Region #Region "Clique do contextMenuStrip Editar" Private Sub editFamilar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Try objBLL = New BLL.AddFamiliaBLL 'String com dados concatenados por "-" '(id_familiar, nome_familiar,parentesco_familiar,nascimento_familiar,profissao_familiar) Dim str As String = objBLL.buscaFamiliarId(dgFamiliares.Rows(linha).Cells(0).Value) Dim arrStr() As String = Split(str, "-") idFamiliar = arrStr(0) txtNome.Text = arrStr(1) txtParentesco.Text = arrStr(2) mtbNascimento.Text = arrStr(3) txtProfissao.Text = arrStr(4) btAdicionar.Text = "Atualizar" cmsFamilia.Enabled = False Catch ex As Exception MessageBox.Show(ex.Message) Finally objBLL = Nothing End Try End Sub #End Region #Region "Clique do contextMenuStrip Deletar" Private Sub deletFamiliar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If (MsgBox("Deseja deletar o familiar: " & dgFamiliares.Rows(linha).Cells(1).Value, MsgBoxStyle.YesNo, "Deletar Familiar") = Windows.Forms.DialogResult.Yes) Then Try objBLL = New BLL.AddFamiliaBLL objBLL.deletaFamiliar(dgFamiliares.Rows(linha).Cells(0).Value) carregaGrid() Catch ex As Exception MessageBox.Show(ex.Message) Finally objBLL = Nothing End Try End If End Sub #End Region #Region "Quando o mouse entra no gridView CellMouseEnter" Private Sub dgFamiliares_CellMouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgFamiliares.CellMouseEnter linha = e.RowIndex End Sub #End Region #Region "Quando e trocado o valor do combobox Familia" Private Sub cbFamilia_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbFamilia.SelectionChangeCommitted carregaGrid() End Sub #End Region #Region "Clique do Label Adicionar nova Familia" Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click habilita(False) End Sub #End Region #Region "Clique do botão familiaCancela" Private Sub btFamiliaCancela_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btFamiliaCancela.Click habilita(True) End Sub #End Region #Region "Clique do botão familiaAdiciona" Private Sub btFamilia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btFamilia.Click Try If txtNomeFamilia.Text <> "" Then objBLL = New BLL.AddFamiliaBLL objBLL.insereNovaFamilia(txtNomeFamilia.Text, recebeAI) cbFamilia.DataSource = Nothing preencherCombo() habilita(True) Else MessageBox.Show("Preencha o nome da familia corretamente.") End If Catch ex As Exception MessageBox.Show(ex.Message) Finally objBLL = Nothing End Try End Sub #End Region #End Region End Class