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. Visual Basic
  4. Using formula in DataGridView

Using formula in DataGridView

Scheduled Pinned Locked Moved Visual Basic
databasequestionannouncement
3 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.
  • A Offline
    A Offline
    Amanjot
    wrote on last edited by
    #1

    Hi, I have an Access Data table with three fields (date, tippingB, and precip). I am using dataGridView to view this table and make changes. The third field in the table (precip) is dependent on second field (tippingB). I was wondering if there is a way to use a formula in the field so that when I put a number in the second field, third field automatically gets updated. The last step of the code is updating the access table in the access database (that works so far). So, my question is if one could use a formula for a column in a dataGridView and also bind it to the dataTable so that when update command is used, the database gets updated. Thanks, Amanjot

    D V 2 Replies Last reply
    0
    • A Amanjot

      Hi, I have an Access Data table with three fields (date, tippingB, and precip). I am using dataGridView to view this table and make changes. The third field in the table (precip) is dependent on second field (tippingB). I was wondering if there is a way to use a formula in the field so that when I put a number in the second field, third field automatically gets updated. The last step of the code is updating the access table in the access database (that works so far). So, my question is if one could use a formula for a column in a dataGridView and also bind it to the dataTable so that when update command is used, the database gets updated. Thanks, Amanjot

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The DGV is not Excel. There are no formula you can put into a cell. Your code has to handle the CellValueChanged[^] event. You can then get the row and cell that changed from the event args, do your calculation and update the appropriate cell.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • A Amanjot

        Hi, I have an Access Data table with three fields (date, tippingB, and precip). I am using dataGridView to view this table and make changes. The third field in the table (precip) is dependent on second field (tippingB). I was wondering if there is a way to use a formula in the field so that when I put a number in the second field, third field automatically gets updated. The last step of the code is updating the access table in the access database (that works so far). So, my question is if one could use a formula for a column in a dataGridView and also bind it to the dataTable so that when update command is used, the database gets updated. Thanks, Amanjot

        V Offline
        V Offline
        VJ Reddy
        wrote on last edited by
        #3

        The answer given by Dave Kreskowiak is absolutely correct. An alternative is to use Expression property of precip DataColumn object to calculate the value based on the value of the tippingB DataColumn as explained here DataColumn.Expression Property[^] After binding the DataTable to the DataGridView the calculated value in the precip column will be displayed in the DataGridView.

        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