Determining whether the user selected a different row on datagrid

Posted on 2004-11-01
Last Modified: 2010-04-15

is there a simple way to determine whether the user clicked on a different row inside the datagrid?


Question by:brdrok
    LVL 2

    Accepted Solution

    You could use the property currentrowindex of the datagrid and the event CurrentCellChanged. Also you need to add a variable to know if the selection is a new row or just a new cell.

    int LastRow = 0;


    private void grid1_CurrentCellChanged(object sender, System.EventArgs e)
        if(LastRow != grid1.CurrentRowIndex)
               LastRow = grid1.CurrentRowIndex;

               // ROW CHANGED--- wrtie your code here

    Expert Comment

    Do you mean if someone clicks on a different row? whether they click update button or similar?

    Well basically with most events in the Datagrid you have the arguements in the Event handler you can find out which row has been selected from that ....

    e.Item.Cells[0] is the first cell data... 0 being the index of the cell...

    This way for any type of command or event you can know if the row has been changed.
    LVL 7

    Author Comment

    thanks dsabo....

    worked out pretty good.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    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…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    913 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

    16 Experts available now in Live!

    Get 1:1 Help Now