insert the column to datagrid view at runtime in vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nithya jayaraman
    New Member
    • Jul 2007
    • 7

    insert the column to datagrid view at runtime in vb.net

    Hi

    the purchase order have list of items and quantity ....
    i want to dispatch this to many city

    for example

    the order have 3 item
    A- 20 quantity
    B- 30 Qty
    C-40 Qty
    Dispatch Detail

    Shipment 1

    A- 20 qty
    B-10 Qty
    C-30 Qty

    Shipment 2
    A- 0 qty
    B-10 Qty
    C-10 Qty

    Shipment 3
    A-0 Qty
    B-10 Qty
    C-0

    The Grid Display in this format, the item name quantities are take over from database , the shipment detail is received from user . based upon that we need to create the Shipment column every time

    Item Qty Shipment1 Shipment 2 Shipment 3 shipment4 total
    A 20 20 0 0 20
    B 30 10 10 10 30
    C 40 30 10 0 40

    Total 90 60 20 10 90

    and also display the grand total in item wise and shipment wise
    the number of shipment change based upon the customer order

    plz help me
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    You are asking several questions here. First let's get you on the right track to create new columns for each Shipment. In the page_load event you will need to identify how many shipments need to be displayed which will give you the number of columns that need to be added to your datagrid. Once you have that number let's use your example and say you need 4 new shipment columns you will want to dynamically create the datagrid columns. (NOTE: I am assuming the number displayed under each Shipment column will be populated from the database). You will need to use a loop to create a new BoundColumn for each new shipment column.

    Code:
     int numShipments = 4; 
    for(int i =1;i<=numShipments; i++)
    {
    BoundColumn bc = new BoundColumn();
    bc.DataField = "shipment_data"; //this will be the column in your dataset for the shipment information
    bc.HeaderText = "Shipment" + i; 
    DataGrid1.Columns.Add(bc);
    }
    DataGrid1.DataSource = dataset; //this is the dataset you use originally to bind the other columns (not shipment columns) to the grid.
    DataGrid1.DataBind();
    Try to get this working. Then search the web for displaying columns totals in a datagrid. If you get stuck on something specific let us know.

    Nathan

    Comment

    Working...