Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. deselect a row

deselect a row

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FernandoMartin
    wrote on last edited by
    #1

    hello, I want to deselect a row in the datagridview, and I'm using the code: if ( dgv[ hti.ColumnIndex, hti.RowIndex ].Selected ) { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = false; } else { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = true; } this code is in the DatagridView_MouseClick. the code does not work, anybody knows why? thank you

    G G 3 Replies Last reply
    0
    • F FernandoMartin

      hello, I want to deselect a row in the datagridview, and I'm using the code: if ( dgv[ hti.ColumnIndex, hti.RowIndex ].Selected ) { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = false; } else { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = true; } this code is in the DatagridView_MouseClick. the code does not work, anybody knows why? thank you

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      First of all you could have written this like this: dgv[ hti.ColumnIndex, hti.RowIndex ].Selected=!(dgv[ hti.ColumnIndex, hti.RowIndex ].Selected); Secondly, if the row is not selected it will become selected. Do you want this to happen?

      my articles

      1 Reply Last reply
      0
      • F FernandoMartin

        hello, I want to deselect a row in the datagridview, and I'm using the code: if ( dgv[ hti.ColumnIndex, hti.RowIndex ].Selected ) { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = false; } else { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = true; } this code is in the DatagridView_MouseClick. the code does not work, anybody knows why? thank you

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        You can use ClearSelection function of DataGridView

        my articles

        1 Reply Last reply
        0
        • F FernandoMartin

          hello, I want to deselect a row in the datagridview, and I'm using the code: if ( dgv[ hti.ColumnIndex, hti.RowIndex ].Selected ) { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = false; } else { dgv[ hti.ColumnIndex, hti.RowIndex ].Selected = true; } this code is in the DatagridView_MouseClick. the code does not work, anybody knows why? thank you

          G Offline
          G Offline
          ganti r
          wrote on last edited by
          #4

          Hi, this also works dgv[ hti.ColumnIndex, hti.RowIndex ].SelectedIndex = -1

          rAm i Think, i Wait, i Fast -- Siddartha

          F 1 Reply Last reply
          0
          • G ganti r

            Hi, this also works dgv[ hti.ColumnIndex, hti.RowIndex ].SelectedIndex = -1

            rAm i Think, i Wait, i Fast -- Siddartha

            F Offline
            F Offline
            FernandoMartin
            wrote on last edited by
            #5

            the "SelectedIndex" does not exist in this case.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups