datagridview selected event 2008

Posted on 2009-04-21
Last Modified: 2013-11-26
what is the suitable even to fire code , when user selected Datagridview by mouse click
Question by:aarontham
    LVL 11

    Accepted Solution

    You can use either CellClick/CellDoubleClick events for datagrid view.
    Pls look into below link
    LVL 48

    Expert Comment

    What was the problem of RowEnter event ?

    Author Comment

    HI jpaulino,

    The RowEnter event  is not that suitable for me. i have below problem with RowEnter event.
    1)it fire when form load.
    2)i have a textbox do search this Datagridview1 and display result back to the same Datagridview1. when i use RowEnter this search funtion also got problem.
    LVL 48

    Assisted Solution

    Ok, then use CellClick like srikanthreddyn143 suggested, but you should also do a small walkaround to use only for row change:

        Private previousRow As Integer
        Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
            If previousRow <> e.RowIndex Then
                ' your code
            End If
            previousRow = e.RowIndex
        End Sub

    Open in new window


    Author Comment

    Hi jpaulino,

    can you explaint if don't do the small walkaround. what will happen?? i just need to know
    LVL 48

    Expert Comment

    What happen is that when you select one cell, in the same row, it will always update the second datagridview. Its unnecessary and slows the application.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now