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. .NET (Core and Framework)
  4. Subtract number for each row from datagridview1 to datagridview2 and display to answer to datagridview3

Subtract number for each row from datagridview1 to datagridview2 and display to answer to datagridview3

Scheduled Pinned Locked Moved .NET (Core and Framework)
help
2 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.
  • P Offline
    P Offline
    percy05
    wrote on last edited by
    #1

    Hello po. Ito po yung current code ko. Please help po. TIA

        Dim dt As New DataTable()
        dt.Columns.Add("Name")
        dt.Columns.Add("Count")
        Dim manpower1 As Integer
        Dim present1 As Integer
        For Each row As DataGridViewRow In manpower.Rows
            dt.Rows.Add(row.Cells(1).Value)
        Next
        For Each row1 As DataGridViewRow In present.Rows
            present1 = (row1.Cells(1).Value)
            dt.Rows.Add(manpower1 - present1)
        Next
        For Each row2 As DataGridViewRow In manpower.Rows
            dt.Rows.Add(manpower1 - present1)
        Next
        absent.DataSource = dt
    
    L 1 Reply Last reply
    0
    • P percy05

      Hello po. Ito po yung current code ko. Please help po. TIA

          Dim dt As New DataTable()
          dt.Columns.Add("Name")
          dt.Columns.Add("Count")
          Dim manpower1 As Integer
          Dim present1 As Integer
          For Each row As DataGridViewRow In manpower.Rows
              dt.Rows.Add(row.Cells(1).Value)
          Next
          For Each row1 As DataGridViewRow In present.Rows
              present1 = (row1.Cells(1).Value)
              dt.Rows.Add(manpower1 - present1)
          Next
          For Each row2 As DataGridViewRow In manpower.Rows
              dt.Rows.Add(manpower1 - present1)
          Next
          absent.DataSource = dt
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are adding 3 sets of rows to your datatable instead of just 1. Try something like:

      For Int row = manpower.RowCount
      manpower1 = manpower.Rows(row).Columns(1).Value
      present1 = present.Rows(row).Columns(1).Value
      dt.Rows.Add(manpower1 - present1)
      Next
      absent.DataSource = dt

      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