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. Updating Datagrid Cell Value

Updating Datagrid Cell Value

Scheduled Pinned Locked Moved C#
helpdatabaseannouncement
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.
  • U Offline
    U Offline
    User 1560431
    wrote on last edited by
    #1

    Hi All, This probably really easy for somebody out there but this problem is doing my head in! What i want to do is update a a single cell in a in a datarow of a datagrid with a value from a textbox so i don't have use a query to repopulate the datagrid after a update query. What i've tried Updating the DataTable or DataSet from the datagrid before updating with the following code: 1)mydatatable.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0); 2)ds.Tables[0].Columns[0].Table.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0); and then rebind it to the datagrid. My problem is that the "ItemArray.SetValue" method doesn't seem to be updating the value when i check it through the step through debugging. Please help, Thanks in advance confused

    A 1 Reply Last reply
    0
    • U User 1560431

      Hi All, This probably really easy for somebody out there but this problem is doing my head in! What i want to do is update a a single cell in a in a datarow of a datagrid with a value from a textbox so i don't have use a query to repopulate the datagrid after a update query. What i've tried Updating the DataTable or DataSet from the datagrid before updating with the following code: 1)mydatatable.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0); 2)ds.Tables[0].Columns[0].Table.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0); and then rebind it to the datagrid. My problem is that the "ItemArray.SetValue" method doesn't seem to be updating the value when i check it through the step through debugging. Please help, Thanks in advance confused

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

      Dont play with the itemarry. It is handled internally. mydatatable.Rows[lastUpdatedRecord] = int.Parse(txtVal.Text); will do the job. Live Life King Size Alomgir Miah

      L 1 Reply Last reply
      0
      • A Alomgir Miah

        Dont play with the itemarry. It is handled internally. mydatatable.Rows[lastUpdatedRecord] = int.Parse(txtVal.Text); will do the job. Live Life King Size Alomgir Miah

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thank you for your response. My problem is this: mydatatable.Rows[lastUpdatedRecord] = "Needs Type DataRow" DataRow is made up of a array of values, a single value in the array represents a single cell value in the datarow. I just need to update a single cell value in the datarow array. Is there any other way of updating the datagrid without having to query the database? Thanks in advance,

        M 1 Reply Last reply
        0
        • L Lost User

          Thank you for your response. My problem is this: mydatatable.Rows[lastUpdatedRecord] = "Needs Type DataRow" DataRow is made up of a array of values, a single value in the array represents a single cell value in the datarow. I just need to update a single cell value in the datarow array. Is there any other way of updating the datagrid without having to query the database? Thanks in advance,

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          With just one indexer (lastUpdatedRecord) you reference a single row, but when you use 2 indexers, you can access a single cell: mydatatable.Rows[lastUpdatedRecord][columnNumber] = newValue; Regards, mav

          L 1 Reply Last reply
          0
          • M mav northwind

            With just one indexer (lastUpdatedRecord) you reference a single row, but when you use 2 indexers, you can access a single cell: mydatatable.Rows[lastUpdatedRecord][columnNumber] = newValue; Regards, mav

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Sorted...Thanks mav Your A king!

            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