CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    [RESOLVED] key up triggered twice for one keystroke

    I have this datagridview called dgSubregels on my form.
    Editmode is set on EditOnEnter

    If I press the F2 or F5 key in a certain cell (subArtcode = 2) this should be triggered.
    In that case a form is loaded with another datagridview filled with data
    On the cell doubleclick of that one the data should return.
    This does work, and the passed data does show up into the datagridview, but somehow the event is triggered also after filling in those values, because frmArtikel is opening again after I doubleclick on a cell.

    What should I change to let the event trigger only once ?

    Code:
    //mainform
            private void dgSubregels_KeyUp(object sender, KeyEventArgs e)
            {
                int Rij, Cel;
                Rij = dgSubregels.CurrentCell.RowIndex;
                Cel = dgSubregels.CurrentCell.ColumnIndex;
                if (Convert.ToInt16(e.KeyCode) == KeyF2 || Convert.ToInt16(e.KeyCode) == KeyF5)
                {
    
                    if (Cel == subArtcode)
                    {
                        frmArtikel frmArt = new frmArtikel(dgKop.Left + this.Left + 100, dgKop.Top + this.Top + 50,this);
                        if (frmArt.ShowDialog(this) == DialogResult.OK)
                        {
                            dgSubregels.Rows[Rij].Cells[subArtcode].Value = frmArt.SelectedArtikel[0];
                            dgSubregels.Rows[Rij].Cells[subArtDesc].Value = frmArt.SelectedArtikel[1];
                        }
                        frmArt.Dispose();
                    }
                }
            }
    
    //frmArtikel
            private void dgArtikelen_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
            {
                int SelectedRow = dgArtikelen.SelectedRows[0].Index;
                for (int i = 0; i < 9; i++)
                {
                    SelectedArtikel[i] = dgArtikelen.Rows[SelectedRow].Cells[i].Value.ToString();
                }
                this.DialogResult = DialogResult.OK;
            }

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: key up triggered twice for one keystroke

    Are you trying to double click on the cell in the frmArtikel form? If it is then how come that form itself will showup or are you double clicking on the parent form where the datagridview exists ?

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    Re: key up triggered twice for one keystroke

    No, on F2 or F5 in the grid from the mainform the frmArtikel will show

    On a double click in a cell of the grid in frmArtikel causes frmArtikel to close
    The code for mainform and form frmArtikel is on the post under eachother but not in my code ofcourse


    So : mainform => keyup
    childform => doubleclick

    Found out that when I dont doubleclick the childform but close it the childform comes back also
    Last edited by Teranoz; August 26th, 2009 at 06:38 AM.

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    Re: key up triggered twice for one keystroke

    Found it, I had also code that cought the event for the form

    Code:
            private void frmBoeking_KeyUp(object sender, KeyEventArgs e)
            {
                if (Convert.ToInt16(e.KeyCode) == KeyF2  || Convert.ToInt16(e.KeyCode) == KeyF5 )
                {
                    if (ControlWithFocus == dgKop.Name.ToString())
                    {
                        dgKop_KeyUp(sender, e);
                    }
                    else if (ControlWithFocus == dgSubregels.Name.ToString())
                    {
                        dgSubregels_KeyUp(sender, e);
                    }
                    else if (ControlWithFocus == dgDagboeken.Name.ToString() )
                    {
                       dgDagboeken_KeyUp(sender, e);
                    }
                }
            }
    By removing the keyup event in the control property of the datagridview and leaving the code there its now working ok

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured