Get selected row index when mouse dbl click on any cell row

Posted on 2007-10-19
Last Modified: 2013-12-17
Hi All,

I am working on Visual c# 2.0 application, i have form with DataGridiew that displays data from db,, and i want the user if double click on any row on grid get the index of that column?? how can i do that?

Iam new to desktop app programming so i appreciate any help on this?
Question by:Abu Hamdan
    LVL 96

    Accepted Solution

    Something like this:

            private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
                if (e.Button == MouseButtons.Left)
                    DataGridView.HitTestInfo hitTest = this.dataGridView1.HitTest(e.X, e.Y);

                    if (hitTest != null && hitTest.RowIndex != -1 && hitTest.ColumnIndex != -1)


    LVL 22

    Expert Comment

    Do you want the row index, or the column index?
    Add an event handler for the RowHeaderMouseDoubleClick event if you want the row.
    Add an event handler for OnSelectionChanged event if you want the column.

    LVL 7

    Author Comment

    by:Abu Hamdan
    thanks Bob,, its exatly what i wanted :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now