Windows Forms, double click that opens a new Form

Asked

Viewed 55 times

0

I have a table called Tournament and would like to make Doubleclick on the type of game open all the teams of that game.

I have 4 buttons that represent the 4 games I have, in the 4 games I have the tournaments the teams and the classifications and when entering a tournament I wanted that when I Doubleclick in the game open all the teams of each game that are already by classification in a datagridview.

The code is as follows::

private void Dgv1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (dataGridView1.CurrentCell.ColumnIndex == dataGridView1.Columns["Jogos"].Index)
            {
                EquipasLOL Tela = new EquipasLOL(dataGridView1.SelectedRows[0].Cells["Jogos"].ToString());
                Tela.Show();
                this.Hide();
            }
        }

Thanks for the help!

  • Forms are inside the DMV?

  • Yeah, they’re all inside the DMV, but I can’t seem to make the connection by Doubleclick in the column of the type of game.

1 answer

2


I understood more or less but I’ll do my best.

from what I understand you want in a dataview when given double click it open something a form from what I understand

so you could use the click event along with mause position

Sample Code:

bool Click = false;
Point Cell = new Point(-1, -1);

private void Dgv1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            // Si possivel dezativar o multiselect antes melhor
            DataGridViewHistory.MultiSelect = false;

            // Verifica si esta na coluna certa
            if (dataGridView1.CurrentCell.ColumnIndex != dataGridView1.Columns["Jogos"].Index) return;

            if(Click == false)
            {
                 Click = true;
                 Cell = new Point(DataGridViewHistory.SelectedCells[0].RowIndex, DataGridViewHistory.SelectedCells[0].ColumnIndex);
            }
            else if (Click && Cell == new Point(DataGridViewHistory.SelectedCells[0].RowIndex, DataGridViewHistory.SelectedCells[0].ColumnIndex))
            {
                 Click = false;
                 Tela.Show();
            }
            else if (Click == false)
            {
                 Click = true;
                 Cell = new Point(DataGridViewHistory.SelectedCells[0].RowIndex, DataGridViewHistory.SelectedCells[0].ColumnIndex);
            }
        }

Explanation I created a bool to be able to determine when the 2° click and a point to help store Olum and the Row that was selected and compare themselves was the same cell being clicked.

|> when you click a cell the code arrow the value of the point Cell to that of the selected cell.

|> when you give one more click on the same cell it confers itself and the same cell and if it is the 2 click execulta or opens the form

|> when vc click for 2 time only and in another cell it and arrow for the point of 1° click for it

Any doubt just ask.

Browser other questions tagged

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