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 cell Value

Datagrid cell Value

Scheduled Pinned Locked Moved C#
question
4 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.
  • L Offline
    L Offline
    Lash20
    wrote on last edited by
    #1

    I'm making use of a datagrid, How do you get the current value of a specific cell (row 0, col 0) after the user sorts by clicking on the columnheader? This is what I tried using the MouseUp event but I seem to be getting the value of the cell before the sort. private void dGrdFamily_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //if left mouse is clicked if(e.Button == MouseButtons.Left) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = this.dGrdFamily.HitTest(pt); if(hti.Type == DataGrid.HitTestType.ColumnHeader) { this.textBox2.Text = this.dGrdFamily[0,0].ToString(); } } }

    A M 2 Replies Last reply
    0
    • L Lash20

      I'm making use of a datagrid, How do you get the current value of a specific cell (row 0, col 0) after the user sorts by clicking on the columnheader? This is what I tried using the MouseUp event but I seem to be getting the value of the cell before the sort. private void dGrdFamily_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //if left mouse is clicked if(e.Button == MouseButtons.Left) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = this.dGrdFamily.HitTest(pt); if(hti.Type == DataGrid.HitTestType.ColumnHeader) { this.textBox2.Text = this.dGrdFamily[0,0].ToString(); } } }

      A Offline
      A Offline
      Alomgir Miah
      wrote on last edited by
      #2

      If the DataSource is a DataTable you can use private DataRow GetDataRowAt(int index) { DataRow dataRow = null; CurrencyManager currencyManager = null; currencyManager = (CurrencyManager)this.BindingContext[this.dataTable]; if ( currencyManager != null ) { dataRow = ((DataRowView)currencyManager.List[index]).Row; } return dataRow; } Live Life King Size Alomgir Miah

      L 1 Reply Last reply
      0
      • A Alomgir Miah

        If the DataSource is a DataTable you can use private DataRow GetDataRowAt(int index) { DataRow dataRow = null; CurrencyManager currencyManager = null; currencyManager = (CurrencyManager)this.BindingContext[this.dataTable]; if ( currencyManager != null ) { dataRow = ((DataRowView)currencyManager.List[index]).Row; } return dataRow; } Live Life King Size Alomgir Miah

        L Offline
        L Offline
        Lash20
        wrote on last edited by
        #3

        Hi: Thanks for your help. I tried your suggestion but I came across the same problem. It seems like the MouseUp event that I'm using may not be the best event to use in this case. It seems like it is obtaining the row value prior to the actual sort of the datagrid values. Do you know of any event that I can implement to notify me when a change has occurred in a cell/row value (not change in row index)??

        1 Reply Last reply
        0
        • L Lash20

          I'm making use of a datagrid, How do you get the current value of a specific cell (row 0, col 0) after the user sorts by clicking on the columnheader? This is what I tried using the MouseUp event but I seem to be getting the value of the cell before the sort. private void dGrdFamily_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { //if left mouse is clicked if(e.Button == MouseButtons.Left) { Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = this.dGrdFamily.HitTest(pt); if(hti.Type == DataGrid.HitTestType.ColumnHeader) { this.textBox2.Text = this.dGrdFamily[0,0].ToString(); } } }

          M Offline
          M Offline
          Mr Naveed Butt
          wrote on last edited by
          #4

          Use the datagrid.Refresh() function...

          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