Results 1 to 2 of 2

Thread: [RESOLVED] Help DataGridView Rows[i].Selected Property

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Help DataGridView Rows[i].Selected Property

    Hi guys help please...I have a DataGridView (dgEvents) and I also want the row to be selected if the user right-click on it. So i have the code below to achieve the right-click select

    MouseDown Event Code:
    Code:
            private void dgEvents_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    int indexOver = dgEvents.HitTest(e.X, e.Y).RowIndex;
                    if (indexOver >= 0 && indexOver < dgEvents.RowCount)
                    {
                        dgEvents.Rows[indexOver].Selected = true;
                    }
                    else
                    {
                        dgEvents.ClearSelection();
                    }
                }
            }
    When I try to select a row by using the left-click (mouse left button) the dgEvents.CurrentRow.Index value is right but when i try to use the right-click (mouse right button) the dgEvents.CurrentRow.Index value doesn't change but the highlight is on the row that i've selected (Please see the attched screenshot).

    Code:
            private void dgEvents_SelectionChanged(object sender, EventArgs e)
            {
                MessageBox.Show("Selected Index: " + dgEvents.CurrentRow.Index.ToString());
            }
    Any idea guys on how to solve my problem..Thanks in advance!!!
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help DataGridView Rows[i].Selected Property

    I alreae it....instead of using "dgEvents.CurrentRow" i used "dgEvents.SelectedRows[0].Index"...

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