How can i get a clicked cell's index in a DataGridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hmunawar
    New Member
    • Dec 2007
    • 1

    How can i get a clicked cell's index in a DataGridView

    I m using a data gridveiw control in Window forms application and i want to delete the record on which the user clicks, for this purpose i need to get the index of the clicked row.

    How can i get these.........
    Kindly tell me if anybody has a solution....... ..
  • Airslash
    New Member
    • Nov 2007
    • 221

    #2
    this.datagridvi ew.SelectMode = FullRowSelect // Set this in the proprty manager
    this.datagridvi ew.SelectedRows[0] // is your selected row.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      If need be, there are also events that fire when a cell/row is clicked

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by Hmunawar
        I m using a data gridveiw control in Window forms application and i want to delete the record on which the user clicks, for this purpose i need to get the index of the clicked row.

        How can i get these.........
        Kindly tell me if anybody has a solution....... ..
        There is a "Delete" button that you can add to your GridView as a column...so that if the user wants to delete a row they can click this button.

        This button will thrown a RowDeleting event.
        When you handle this event in your code, you will be passed a variable of type GridViewDeleteE ventArgs. This variable name is "e".

        From this variable you can determine what row the user has picked to delete by retriving the value from the GridViewDeleteE ventArg varaible's RowIndex property:

        IE: e.RowIndex

        Cheers

        -Frinny

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Your post title stated the GridView object, but in your post you refered to it as a windows application, which would make it a DataGridView object.
          I have changed the title of the post to reflect that.

          Comment

          Working...