I want display 1 record become 4 record for print label purpose. For Example, Model A quantity is 100 pcs, every package only can 25pcs. so I want display as attach picture in datagridview in C#.

quantity records is based on Quantity / ItemPerPackage.

hello !
try to use query to get filtered records , and then populate your grid

select customer,Model,Foam,Grade,item,Thick,Width,Length,sum(Qty),25 as ItemPerPackage
from YourTable
group by customer,Model,Foam,Grade,item,Thick,Width,Length

Hope this will help you

Regards

If I understand correctly, here is a console version of what you're attempting.
It makes the assumption that every record has the potential of a different split based on the number of items per package dividing the total items in the order.

It does a Math.Ceiling() to determine how many loops (or records in the output) there will be.

It also does a trick with "strItemPerP" so when the master record is displayed, the actual Items-Per-Package shows, but when the sub-record is displayed, the formula is displayed.

It would be easy to convert this to a DataGridView.

using System;
using System.Collections.Generic;

namespace DW_408869_CS_CON
{
   class CCustomer
   {
      public string strCust { get; set; }
      public string strMdl { get; set; }
      public string strFoamGr { get; set; }
      public int intItem { get; set; }
      public int intThick { get; set; }
      public int intWidth { get; set; }
      public int intLen { get; set; }
      public int intQty { get; set; }
      public int intItemPerP { get; set; }
      public string strItemPerP { get; set; }

      public override string ToString()
      {
         return
            strCust + '\t' + strMdl + '\t' + strFoamGr + '\t' +
            intItem.ToString() + '\t' + intThick.ToString() + '\t' +
            intWidth.ToString() + '\t' + intLen.ToString() + '\t' +
            intQty.ToString() + '\t' + strItemPerP;
      }

      public static string HEADER
      { get { return
         "CUST\tMODEL\tFoamGr\tItem\tThick\tWidth\tLength\tQty\tItemPer";}
      }
   }

   class Program
   {
      static void Main(string[] args)
      {
         List<CCustomer> lstCustomers = new List<CCustomer>()
         {
            new CCustomer(){strCust="XYA", strMdl="Model1", strFoamGr="FoamA",
               intItem=1, intThick=2, intWidth=4, intLen=2, intQty=100, intItemPerP=25},
            new CCustomer(){strCust="XYB", strMdl="Model1", strFoamGr="FoamB",
               intItem=1, intThick=4, intWidth=3, intLen=2, intQty=40, intItemPerP=25},
            new CCustomer(){strCust="XYC", strMdl="Model1", strFoamGr="FoamC",
               intItem=1, intThick=6, intWidth=2, intLen=2, intQty=33, intItemPerP=9},
         };

         Console.WriteLine(CCustomer.HEADER);
         foreach (CCustomer cst in lstCustomers)
         {
            cst.strItemPerP = cst.intItemPerP.ToString();
            Console.WriteLine(cst.ToString());
            //
            int intItemsLeft = cst.intQty;
            int intNumLoops =
               (int)Math.Ceiling(((decimal)cst.intQty / cst.intItemPerP));
            //
            for (int i = 0;(intItemsLeft>0); i++)
            {
               cst.intQty = Math.Min(intItemsLeft, cst.intItemPerP);
               cst.strItemPerP = (i+1).ToString() + '/' + intNumLoops.ToString();
               Console.WriteLine("-" + cst.ToString());
               intItemsLeft -= cst.intItemPerP;
            }

            Console.WriteLine();
         }
      }
   }
}

Of course, I left out a few things I would normally do to a class (with constructors-n-such)

...and of course, since a routine that will render the data as an array of tab-delimited strings, you could do something like this to get it in the DataGridView:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DW_408869_CS_FORM
{
   public partial class Form1 : Form
   {
      private static List<string> _lst_strResults = new List<string>()
      {
         "XYA\tModel1\tFoamA\t1\t2\t4\t2\t100\t25",
         "-XYA\tModel1\tFoamA\t1\t2\t4\t2\t25\t1/4",
         "-XYA\tModel1\tFoamA\t1\t2\t4\t2\t25\t2/4",
         "-XYA\tModel1\tFoamA\t1\t2\t4\t2\t25\t3/4",
         "-XYA\tModel1\tFoamA\t1\t2\t4\t2\t25\t4/4"
      };

      public Form1()
      {
         InitializeComponent();
      }

      private void Form1_Load(object sender, EventArgs e)
      {
         dataGridView1.DataSource =
         (
            from strResult in _lst_strResults
            let arr = strResult.Split('\t')
            select new {
               CUST = arr[0],
               MODEL = arr[1],
               FoamGr = arr[2],
               Item = arr[3],
               Thick = arr[4],
               Width = arr[5],
               Length = arr[6],
               Qty = arr[7],
               ItemPer = arr[8]
            }
         ).ToList();
      }
   }
}

Of course, you would need to modify the style of the columns and rows to look as you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.