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. Add rows from one datagridview to another

Add rows from one datagridview to another

Scheduled Pinned Locked Moved Visual Basic
csharpcssvisual-studiohelptutorial
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.
  • H Offline
    H Offline
    Hansduncan
    wrote on last edited by
    #1

    I am building a windows app to that will keep track of customers, quotes, orders and so forth using VB in visual studio 2005. I have a master-detail form that contains a Quoteheader and Quoteline datagridview that where the users can add products, price, number and so forth. I have also created another form (product search) that enables users to easily filter and search for products to pick the product(s) they want to add to the quote using a checkbox that I added to each row in the grid. (The data for this datagridview is pulled from a seperate dataset based on a view that contains, among other things, the info I need to transfer to the quoteline datagridview). Specifically I want to insert a new row in the Quoteline datagridview on the Quoteform where I automatically add the following field values (articleID, price per unit and costprice) from the product search datagridview to their respective column cells on the quoteline datagridview. It should insert a new row in the qoteline datagridview for each product that is selected using the checkbox on the product search form. I would like some help and advice on how to best code this operation.

    D 1 Reply Last reply
    0
    • H Hansduncan

      I am building a windows app to that will keep track of customers, quotes, orders and so forth using VB in visual studio 2005. I have a master-detail form that contains a Quoteheader and Quoteline datagridview that where the users can add products, price, number and so forth. I have also created another form (product search) that enables users to easily filter and search for products to pick the product(s) they want to add to the quote using a checkbox that I added to each row in the grid. (The data for this datagridview is pulled from a seperate dataset based on a view that contains, among other things, the info I need to transfer to the quoteline datagridview). Specifically I want to insert a new row in the Quoteline datagridview on the Quoteform where I automatically add the following field values (articleID, price per unit and costprice) from the product search datagridview to their respective column cells on the quoteline datagridview. It should insert a new row in the qoteline datagridview for each product that is selected using the checkbox on the product search form. I would like some help and advice on how to best code this operation.

      D Offline
      D Offline
      dptalt
      wrote on last edited by
      #2

      I'm assuming that your datagridview controls are datatable driven. If so, you can create a default view from the product search table while setting a rowfilter on the check box column. Then set the datasource table of the quoteline datagridview equal to this default view.

      H 1 Reply Last reply
      0
      • D dptalt

        I'm assuming that your datagridview controls are datatable driven. If so, you can create a default view from the product search table while setting a rowfilter on the check box column. Then set the datasource table of the quoteline datagridview equal to this default view.

        H Offline
        H Offline
        Hansduncan
        wrote on last edited by
        #3

        I'm not sure, but I don't think what u are suggesting is quite what i am looking for. what i am looking for is the vb.net syntax for how to do something like this: dim aricleid as integer dim productname as string dim productprice as string select articleid, productname, productprice from productsearchform.datagridview where checkboxcolumn.checked=true insert into quoteline.datagridview articleidcolumn, productnamecolumn, productpricecolumn with values (get the declared values from above code) articleid, productname, productprice continue to next row until all rows on the on the productsearch datagrid that have been checked have been inserted as new rows in the quoteline datagridview. Is there a good way to do this?

        D 1 Reply Last reply
        0
        • H Hansduncan

          I'm not sure, but I don't think what u are suggesting is quite what i am looking for. what i am looking for is the vb.net syntax for how to do something like this: dim aricleid as integer dim productname as string dim productprice as string select articleid, productname, productprice from productsearchform.datagridview where checkboxcolumn.checked=true insert into quoteline.datagridview articleidcolumn, productnamecolumn, productpricecolumn with values (get the declared values from above code) articleid, productname, productprice continue to next row until all rows on the on the productsearch datagrid that have been checked have been inserted as new rows in the quoteline datagridview. Is there a good way to do this?

          D Offline
          D Offline
          dptalt
          wrote on last edited by
          #4

          Assume for example, productsearchform.datagridview.datasource = datatableproductsearchform quoteline.datagridview.datasource = datatablequoteline Try this approach: datatableproductsearchform.defaultview.rowfilter = "checkboxcolumn = true" datatablequoteline = datatableproductsearchform.defaultview.totable Or this approach: Add this code to productsearchform.datagridview selectedindexchanged event if productsearchform.SelectedRow.Cells.Item(0).Text = true dim datarownew as datarow datarownew = datatablequoteline.newrow 'use the following code to populate the fields, one per field in datatablequoteline datarownew.item("[field name]") = productsearchform.SelectedRow.Cells.Item(1).Text datatablequoteline.rows.add(datatownew) end if

          H 1 Reply Last reply
          0
          • D dptalt

            Assume for example, productsearchform.datagridview.datasource = datatableproductsearchform quoteline.datagridview.datasource = datatablequoteline Try this approach: datatableproductsearchform.defaultview.rowfilter = "checkboxcolumn = true" datatablequoteline = datatableproductsearchform.defaultview.totable Or this approach: Add this code to productsearchform.datagridview selectedindexchanged event if productsearchform.SelectedRow.Cells.Item(0).Text = true dim datarownew as datarow datarownew = datatablequoteline.newrow 'use the following code to populate the fields, one per field in datatablequoteline datarownew.item("[field name]") = productsearchform.SelectedRow.Cells.Item(1).Text datatablequoteline.rows.add(datatownew) end if

            H Offline
            H Offline
            Hansduncan
            wrote on last edited by
            #5

            Hi Dptalt, The last approach seems to be what I have been looking for. I'll give it a shot later today. Appreciate your help.:) best regards, Hans

            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