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. Windows Forms
  4. how to prevent the user from moving to the clicked cell in DataGridView ?

how to prevent the user from moving to the clicked cell in DataGridView ?

Scheduled Pinned Locked Moved Windows Forms
questiontutorial
5 Posts 4 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.
  • A Offline
    A Offline
    alladeen
    wrote on last edited by
    #1

    hi The default behavior of the DataGridView is that : when the user click on a cell the focus will move to the clicked cell . I want to modify this behavior , so if the user click on a cell the focus will not move to the clicked cell how can i do that thanks

    M A 2 Replies Last reply
    0
    • A alladeen

      hi The default behavior of the DataGridView is that : when the user click on a cell the focus will move to the clicked cell . I want to modify this behavior , so if the user click on a cell the focus will not move to the clicked cell how can i do that thanks

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      You can make the column read only, it then won't accept the click. I think you can make the cell read only but you need to do that on the cell paint event (not sure if thats the correct event), then you can evaluate the cell content and change the properties. If you make the underlying collection (datatable of BindingSource) read only (cannot add/edit/delete) then I believe this will be reflected in the DGV. There are many ways to kill a cat other than drowning it in milk.

      Never underestimate the power of human stupidity RAH

      A 1 Reply Last reply
      0
      • M Mycroft Holmes

        You can make the column read only, it then won't accept the click. I think you can make the cell read only but you need to do that on the cell paint event (not sure if thats the correct event), then you can evaluate the cell content and change the properties. If you make the underlying collection (datatable of BindingSource) read only (cannot add/edit/delete) then I believe this will be reflected in the DGV. There are many ways to kill a cat other than drowning it in milk.

        Never underestimate the power of human stupidity RAH

        A Offline
        A Offline
        alladeen
        wrote on last edited by
        #3

        hi Mycroft Holmes I don't want the value In my underlying Collection to be read only ? thanks

        M 1 Reply Last reply
        0
        • A alladeen

          hi Mycroft Holmes I don't want the value In my underlying Collection to be read only ? thanks

          M Offline
          M Offline
          molesworth
          wrote on last edited by
          #4

          If you have some other control you want to keep focus on, you might just have to manually reset it.

          There are three kinds of people in the world - those who can count and those who can't...

          1 Reply Last reply
          0
          • A alladeen

            hi The default behavior of the DataGridView is that : when the user click on a cell the focus will move to the clicked cell . I want to modify this behavior , so if the user click on a cell the focus will not move to the clicked cell how can i do that thanks

            A Offline
            A Offline
            AhmedMasum
            wrote on last edited by
            #5

            You can disable the full datagridview as you don't want to make it readonly.

            dataGridView1.Enabled = false;

            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