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. Row select on DataGridView

Row select on DataGridView

Scheduled Pinned Locked Moved C#
cssdatabasequestion
5 Posts 2 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.
  • W Offline
    W Offline
    waddie1
    wrote on last edited by
    #1

    Hey guys I have a datagridview populated with entries from a database. I have set the selection mode of the grid to fullrowselect so that a click on any cell will cause selection of that row. In this selection event I open a new form showing the data contained in that row. This works fine, however when you click on a column header it still tries to select that row. Is there any way of stopping this? Thanks in advance

    J 1 Reply Last reply
    0
    • W waddie1

      Hey guys I have a datagridview populated with entries from a database. I have set the selection mode of the grid to fullrowselect so that a click on any cell will cause selection of that row. In this selection event I open a new form showing the data contained in that row. This works fine, however when you click on a column header it still tries to select that row. Is there any way of stopping this? Thanks in advance

      J Offline
      J Offline
      joon vh
      wrote on last edited by
      #2

      What event are you using? I used the doubleClick event somewhere in an old app, and it just refers to the SelectedItem in the datagrid. Then if you doubleclick the header, it just opens the record that was selected last.


      Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

      W 1 Reply Last reply
      0
      • J joon vh

        What event are you using? I used the doubleClick event somewhere in an old app, and it just refers to the SelectedItem in the datagrid. Then if you doubleclick the header, it just opens the record that was selected last.


        Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

        W Offline
        W Offline
        waddie1
        wrote on last edited by
        #3

        I was using the selectionChanged event of the datagrid, is there anyway of knowing which row the selection was made on? ie if row is header row type then do nothing?

        J 1 Reply Last reply
        0
        • W waddie1

          I was using the selectionChanged event of the datagrid, is there anyway of knowing which row the selection was made on? ie if row is header row type then do nothing?

          J Offline
          J Offline
          joon vh
          wrote on last edited by
          #4

          you could use an event like CellClick or RowEnter, they have DataGridViewCellEventArgs where you can access the ColumnIndex and the RowIndex of the selection.

                  private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
                  {
                      // e.RowIndex
                      // e.ColumnIndex
                  }
          

          Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

          W 1 Reply Last reply
          0
          • J joon vh

            you could use an event like CellClick or RowEnter, they have DataGridViewCellEventArgs where you can access the ColumnIndex and the RowIndex of the selection.

                    private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
                    {
                        // e.RowIndex
                        // e.ColumnIndex
                    }
            

            Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

            W Offline
            W Offline
            waddie1
            wrote on last edited by
            #5

            Cheers that does the trick

            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