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. DataGrid "logical" row from HitTest

DataGrid "logical" row from HitTest

Scheduled Pinned Locked Moved C#
cssquestion
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.
  • A Offline
    A Offline
    ABean
    wrote on last edited by
    #1

    Guys, On the datagrid when you do a HitTest you get the "physical" row that the mouse is over. If the user has sorted the grid (by clicking on one of the column headers) and changed the order of the rows is there a way to get the "logical" row from the "physical" row? Thanks

    H 1 Reply Last reply
    0
    • A ABean

      Guys, On the datagrid when you do a HitTest you get the "physical" row that the mouse is over. If the user has sorted the grid (by clicking on one of the column headers) and changed the order of the rows is there a way to get the "logical" row from the "physical" row? Thanks

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Get the DataView used to sort the data. If you bound your DataGrid to a DataView, you're already done. If not, get the DataTable you're binding to (whether it's the DataSource or it's name is the DataMember) and get the DefaultView property.

      Microsoft MVP, Visual C# My Articles

      A 1 Reply Last reply
      0
      • H Heath Stewart

        Get the DataView used to sort the data. If you bound your DataGrid to a DataView, you're already done. If not, get the DataTable you're binding to (whether it's the DataSource or it's name is the DataMember) and get the DefaultView property.

        Microsoft MVP, Visual C# My Articles

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

        Thanks Heath, I'm binding to a DataTable. I've looked at the DefaultView property as well as the other properties of the DataTable but I am unsure how to translate the HitTest Row number from the DataGrid into a row number of the DataTable. I need to get the DataTable row number integer not to update the actual row in the control but to update an associated array. (DataTable row number is the index into the array.) I looked at the Find property but the rows displayed in the table are not unique. It this translation possible?

        A H 2 Replies Last reply
        0
        • A ABean

          Thanks Heath, I'm binding to a DataTable. I've looked at the DefaultView property as well as the other properties of the DataTable but I am unsure how to translate the HitTest Row number from the DataGrid into a row number of the DataTable. I need to get the DataTable row number integer not to update the actual row in the control but to update an associated array. (DataTable row number is the index into the array.) I looked at the Find property but the rows displayed in the table are not unique. It this translation possible?

          A Offline
          A Offline
          ABean
          wrote on last edited by
          #4

          I did some more reading and it looks like I need to put a primary key column on my table - and then I guess I will hide it. But even if I add the primary key column how do I resolve the HitTest Row number from the DataGrid into a DataTable row number?

          1 Reply Last reply
          0
          • A ABean

            Thanks Heath, I'm binding to a DataTable. I've looked at the DefaultView property as well as the other properties of the DataTable but I am unsure how to translate the HitTest Row number from the DataGrid into a row number of the DataTable. I need to get the DataTable row number integer not to update the actual row in the control but to update an associated array. (DataTable row number is the index into the array.) I looked at the Find property but the rows displayed in the table are not unique. It this translation possible?

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            IIRC, you should be able to get it using DataView[physicalRowIndex]. This gets you a DataRowView. Get the Row property to get the actual DataRow, though if you just want the value of a column in the row, you can get it as you would with a DataRow using the DataRowView.

            Microsoft MVP, Visual C# My Articles

            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