Unable to display incremented value in a List in C#












1















I am having a LIST. I am retrieving 1 record each time.



Image Description



Code



List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
int index = 1;
GetClientImpressionProductSel.Clear();
generateSeqNumber();

foreach (var ProdSelection in ClientImpressionProdSelection)
{
for (index = 1; index <= InputProduct.NdPlettes;)
{
ProdSelection.Sequence = Convert.ToInt32(GenResult);
ProdSelection.Number = index;
ProdSelection.ClientDestinataire = InputProduct.ClientDestinataire;
ProdSelection.LieuDeLivraison = InputProduct.LieuDeLivraison;
ProdSelection.CodeProduitClient = InputProduct.CodeProduitClient;
ProdSelection.CodeCouleurClient = InputProduct.CodeCouleurClient;
ProdSelection.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
ProdSelection.AQP = InputProduct.AQP;
ProdSelection.Produit = InputProduct.Produit;
ProdSelection.RefFournisseur = InputProduct.RefFournisseur;
ProdSelection.NdShipment = InputProduct.NdShipment.Value;
ProdSelection.NdLot = InputProduct.NdLot;
ProdSelection.Cdate = InputProduct.Cdate;
ProdSelection.PoidsNet = InputProduct.PoidsNet;
ProdSelection.PoidsBrut = InputProduct.PoidsBrut;
ProdSelection.NbrPallet = InputProduct.NdPlettes.Value;
ProdSelection.Material = InputProduct.Material;
ProdSelection.CodClient = InputProduct.CodClient;
ProdSelection.CodPackaging = InputProduct.CodPackaging;
ProdSelection.CoefNetBrut = InputProduct.CoefNetBrut;
index++;
GetClientImpressionProductSel.Add(ProdSelection);
}

CalculateGrossWeight(ProdSelection);
}


Problem :



I am able to generate N times the records but when I am trying to print a NUMBer , I am always getting last value. Please see the Image attached in the question. The second column is NUM and I am getting 4,4,4,4 instead of 1,2,3,4.



Expected result should be :



Seq                    NUM
180001021 1
180001021 2
180001021 3
180001021 4


Can anyone please help me out?



I have a list. I will always get only 1 record in a list. But if user enter InputProduct.NdPlettes value = N(Number of times) it will get repeated and display.










share|improve this question




















  • 1





    Omg this post was a mess, please take time to edit your question correctly in the future, it makes all the difference.

    – Michael Randall
    Nov 20 '18 at 6:45


















1















I am having a LIST. I am retrieving 1 record each time.



Image Description



Code



List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
int index = 1;
GetClientImpressionProductSel.Clear();
generateSeqNumber();

foreach (var ProdSelection in ClientImpressionProdSelection)
{
for (index = 1; index <= InputProduct.NdPlettes;)
{
ProdSelection.Sequence = Convert.ToInt32(GenResult);
ProdSelection.Number = index;
ProdSelection.ClientDestinataire = InputProduct.ClientDestinataire;
ProdSelection.LieuDeLivraison = InputProduct.LieuDeLivraison;
ProdSelection.CodeProduitClient = InputProduct.CodeProduitClient;
ProdSelection.CodeCouleurClient = InputProduct.CodeCouleurClient;
ProdSelection.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
ProdSelection.AQP = InputProduct.AQP;
ProdSelection.Produit = InputProduct.Produit;
ProdSelection.RefFournisseur = InputProduct.RefFournisseur;
ProdSelection.NdShipment = InputProduct.NdShipment.Value;
ProdSelection.NdLot = InputProduct.NdLot;
ProdSelection.Cdate = InputProduct.Cdate;
ProdSelection.PoidsNet = InputProduct.PoidsNet;
ProdSelection.PoidsBrut = InputProduct.PoidsBrut;
ProdSelection.NbrPallet = InputProduct.NdPlettes.Value;
ProdSelection.Material = InputProduct.Material;
ProdSelection.CodClient = InputProduct.CodClient;
ProdSelection.CodPackaging = InputProduct.CodPackaging;
ProdSelection.CoefNetBrut = InputProduct.CoefNetBrut;
index++;
GetClientImpressionProductSel.Add(ProdSelection);
}

CalculateGrossWeight(ProdSelection);
}


Problem :



I am able to generate N times the records but when I am trying to print a NUMBer , I am always getting last value. Please see the Image attached in the question. The second column is NUM and I am getting 4,4,4,4 instead of 1,2,3,4.



Expected result should be :



Seq                    NUM
180001021 1
180001021 2
180001021 3
180001021 4


Can anyone please help me out?



I have a list. I will always get only 1 record in a list. But if user enter InputProduct.NdPlettes value = N(Number of times) it will get repeated and display.










share|improve this question




















  • 1





    Omg this post was a mess, please take time to edit your question correctly in the future, it makes all the difference.

    – Michael Randall
    Nov 20 '18 at 6:45
















1












1








1








I am having a LIST. I am retrieving 1 record each time.



Image Description



Code



List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
int index = 1;
GetClientImpressionProductSel.Clear();
generateSeqNumber();

foreach (var ProdSelection in ClientImpressionProdSelection)
{
for (index = 1; index <= InputProduct.NdPlettes;)
{
ProdSelection.Sequence = Convert.ToInt32(GenResult);
ProdSelection.Number = index;
ProdSelection.ClientDestinataire = InputProduct.ClientDestinataire;
ProdSelection.LieuDeLivraison = InputProduct.LieuDeLivraison;
ProdSelection.CodeProduitClient = InputProduct.CodeProduitClient;
ProdSelection.CodeCouleurClient = InputProduct.CodeCouleurClient;
ProdSelection.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
ProdSelection.AQP = InputProduct.AQP;
ProdSelection.Produit = InputProduct.Produit;
ProdSelection.RefFournisseur = InputProduct.RefFournisseur;
ProdSelection.NdShipment = InputProduct.NdShipment.Value;
ProdSelection.NdLot = InputProduct.NdLot;
ProdSelection.Cdate = InputProduct.Cdate;
ProdSelection.PoidsNet = InputProduct.PoidsNet;
ProdSelection.PoidsBrut = InputProduct.PoidsBrut;
ProdSelection.NbrPallet = InputProduct.NdPlettes.Value;
ProdSelection.Material = InputProduct.Material;
ProdSelection.CodClient = InputProduct.CodClient;
ProdSelection.CodPackaging = InputProduct.CodPackaging;
ProdSelection.CoefNetBrut = InputProduct.CoefNetBrut;
index++;
GetClientImpressionProductSel.Add(ProdSelection);
}

CalculateGrossWeight(ProdSelection);
}


Problem :



I am able to generate N times the records but when I am trying to print a NUMBer , I am always getting last value. Please see the Image attached in the question. The second column is NUM and I am getting 4,4,4,4 instead of 1,2,3,4.



Expected result should be :



Seq                    NUM
180001021 1
180001021 2
180001021 3
180001021 4


Can anyone please help me out?



I have a list. I will always get only 1 record in a list. But if user enter InputProduct.NdPlettes value = N(Number of times) it will get repeated and display.










share|improve this question
















I am having a LIST. I am retrieving 1 record each time.



Image Description



Code



List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
int index = 1;
GetClientImpressionProductSel.Clear();
generateSeqNumber();

foreach (var ProdSelection in ClientImpressionProdSelection)
{
for (index = 1; index <= InputProduct.NdPlettes;)
{
ProdSelection.Sequence = Convert.ToInt32(GenResult);
ProdSelection.Number = index;
ProdSelection.ClientDestinataire = InputProduct.ClientDestinataire;
ProdSelection.LieuDeLivraison = InputProduct.LieuDeLivraison;
ProdSelection.CodeProduitClient = InputProduct.CodeProduitClient;
ProdSelection.CodeCouleurClient = InputProduct.CodeCouleurClient;
ProdSelection.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
ProdSelection.AQP = InputProduct.AQP;
ProdSelection.Produit = InputProduct.Produit;
ProdSelection.RefFournisseur = InputProduct.RefFournisseur;
ProdSelection.NdShipment = InputProduct.NdShipment.Value;
ProdSelection.NdLot = InputProduct.NdLot;
ProdSelection.Cdate = InputProduct.Cdate;
ProdSelection.PoidsNet = InputProduct.PoidsNet;
ProdSelection.PoidsBrut = InputProduct.PoidsBrut;
ProdSelection.NbrPallet = InputProduct.NdPlettes.Value;
ProdSelection.Material = InputProduct.Material;
ProdSelection.CodClient = InputProduct.CodClient;
ProdSelection.CodPackaging = InputProduct.CodPackaging;
ProdSelection.CoefNetBrut = InputProduct.CoefNetBrut;
index++;
GetClientImpressionProductSel.Add(ProdSelection);
}

CalculateGrossWeight(ProdSelection);
}


Problem :



I am able to generate N times the records but when I am trying to print a NUMBer , I am always getting last value. Please see the Image attached in the question. The second column is NUM and I am getting 4,4,4,4 instead of 1,2,3,4.



Expected result should be :



Seq                    NUM
180001021 1
180001021 2
180001021 3
180001021 4


Can anyone please help me out?



I have a list. I will always get only 1 record in a list. But if user enter InputProduct.NdPlettes value = N(Number of times) it will get repeated and display.







c#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 6:44









Michael Randall

32.4k63565




32.4k63565










asked Nov 20 '18 at 6:41









NamanNaman

67




67








  • 1





    Omg this post was a mess, please take time to edit your question correctly in the future, it makes all the difference.

    – Michael Randall
    Nov 20 '18 at 6:45
















  • 1





    Omg this post was a mess, please take time to edit your question correctly in the future, it makes all the difference.

    – Michael Randall
    Nov 20 '18 at 6:45










1




1





Omg this post was a mess, please take time to edit your question correctly in the future, it makes all the difference.

– Michael Randall
Nov 20 '18 at 6:45







Omg this post was a mess, please take time to edit your question correctly in the future, it makes all the difference.

– Michael Randall
Nov 20 '18 at 6:45














2 Answers
2






active

oldest

votes


















2














I am going have a major guess, your problem is not in the code you supplied, its in the GetClientImpressionProductSelection call.



When you call GetClientImpressionProductSelection it is giving you the same ClientImpressionProductSelectionM in a list.



You are not creating a new ClientImpressionProductSelectionM for each element in your list.



When you are updating the each element,



foreach (var ProdSelection in ClientImpressionProdSelection)


you are just updating the only instantiated object. Hence you are receiving the last result






share|improve this answer
























  • Yes , your understanding is correct. where i can add my creation code inside loop?

    – Naman
    Nov 20 '18 at 6:57



















1














Try like this:



List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
int index = 1;
GetClientImpressionProductSel.Clear();
generateSeqNumber();

foreach (var ProdSelection in ClientImpressionProdSelection)
{
for (index = 1; index <= InputProduct.NdPlettes;)
{
ClientImpressionProductSelectionM prd = new ClientImpressionProductSelectionM();
prd.Sequence = Convert.ToInt32(GenResult);
prd.Number = index;
prd.ClientDestinataire = InputProduct.ClientDestinataire;
prd.LieuDeLivraison = InputProduct.LieuDeLivraison;
prd.CodeProduitClient = InputProduct.CodeProduitClient;
prd.CodeCouleurClient = InputProduct.CodeCouleurClient;
prd.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
prd.AQP = InputProduct.AQP;
prd.Produit = InputProduct.Produit;
prd.RefFournisseur = InputProduct.RefFournisseur;
prd.NdShipment = InputProduct.NdShipment.Value;
prd.NdLot = InputProduct.NdLot;
prd.Cdate = InputProduct.Cdate;
prd.PoidsNet = InputProduct.PoidsNet;
prd.PoidsBrut = InputProduct.PoidsBrut;
prd.NbrPallet = InputProduct.NdPlettes.Value;
prd.Material = InputProduct.Material;
prd.CodClient = InputProduct.CodClient;
prd.CodPackaging = InputProduct.CodPackaging;
prd.CoefNetBrut = InputProduct.CoefNetBrut;
index++;
GetClientImpressionProductSel.Add(prd);
}

CalculateGrossWeight(ProdSelection);
}


You need to create a new instance of the object that you want to add to your list, otherwise it will add a reference to the same object and that is why you get the same values.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387569%2funable-to-display-incremented-value-in-a-list-in-c-sharp%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I am going have a major guess, your problem is not in the code you supplied, its in the GetClientImpressionProductSelection call.



    When you call GetClientImpressionProductSelection it is giving you the same ClientImpressionProductSelectionM in a list.



    You are not creating a new ClientImpressionProductSelectionM for each element in your list.



    When you are updating the each element,



    foreach (var ProdSelection in ClientImpressionProdSelection)


    you are just updating the only instantiated object. Hence you are receiving the last result






    share|improve this answer
























    • Yes , your understanding is correct. where i can add my creation code inside loop?

      – Naman
      Nov 20 '18 at 6:57
















    2














    I am going have a major guess, your problem is not in the code you supplied, its in the GetClientImpressionProductSelection call.



    When you call GetClientImpressionProductSelection it is giving you the same ClientImpressionProductSelectionM in a list.



    You are not creating a new ClientImpressionProductSelectionM for each element in your list.



    When you are updating the each element,



    foreach (var ProdSelection in ClientImpressionProdSelection)


    you are just updating the only instantiated object. Hence you are receiving the last result






    share|improve this answer
























    • Yes , your understanding is correct. where i can add my creation code inside loop?

      – Naman
      Nov 20 '18 at 6:57














    2












    2








    2







    I am going have a major guess, your problem is not in the code you supplied, its in the GetClientImpressionProductSelection call.



    When you call GetClientImpressionProductSelection it is giving you the same ClientImpressionProductSelectionM in a list.



    You are not creating a new ClientImpressionProductSelectionM for each element in your list.



    When you are updating the each element,



    foreach (var ProdSelection in ClientImpressionProdSelection)


    you are just updating the only instantiated object. Hence you are receiving the last result






    share|improve this answer













    I am going have a major guess, your problem is not in the code you supplied, its in the GetClientImpressionProductSelection call.



    When you call GetClientImpressionProductSelection it is giving you the same ClientImpressionProductSelectionM in a list.



    You are not creating a new ClientImpressionProductSelectionM for each element in your list.



    When you are updating the each element,



    foreach (var ProdSelection in ClientImpressionProdSelection)


    you are just updating the only instantiated object. Hence you are receiving the last result







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 '18 at 6:52









    Michael RandallMichael Randall

    32.4k63565




    32.4k63565













    • Yes , your understanding is correct. where i can add my creation code inside loop?

      – Naman
      Nov 20 '18 at 6:57



















    • Yes , your understanding is correct. where i can add my creation code inside loop?

      – Naman
      Nov 20 '18 at 6:57

















    Yes , your understanding is correct. where i can add my creation code inside loop?

    – Naman
    Nov 20 '18 at 6:57





    Yes , your understanding is correct. where i can add my creation code inside loop?

    – Naman
    Nov 20 '18 at 6:57













    1














    Try like this:



    List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
    int index = 1;
    GetClientImpressionProductSel.Clear();
    generateSeqNumber();

    foreach (var ProdSelection in ClientImpressionProdSelection)
    {
    for (index = 1; index <= InputProduct.NdPlettes;)
    {
    ClientImpressionProductSelectionM prd = new ClientImpressionProductSelectionM();
    prd.Sequence = Convert.ToInt32(GenResult);
    prd.Number = index;
    prd.ClientDestinataire = InputProduct.ClientDestinataire;
    prd.LieuDeLivraison = InputProduct.LieuDeLivraison;
    prd.CodeProduitClient = InputProduct.CodeProduitClient;
    prd.CodeCouleurClient = InputProduct.CodeCouleurClient;
    prd.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
    prd.AQP = InputProduct.AQP;
    prd.Produit = InputProduct.Produit;
    prd.RefFournisseur = InputProduct.RefFournisseur;
    prd.NdShipment = InputProduct.NdShipment.Value;
    prd.NdLot = InputProduct.NdLot;
    prd.Cdate = InputProduct.Cdate;
    prd.PoidsNet = InputProduct.PoidsNet;
    prd.PoidsBrut = InputProduct.PoidsBrut;
    prd.NbrPallet = InputProduct.NdPlettes.Value;
    prd.Material = InputProduct.Material;
    prd.CodClient = InputProduct.CodClient;
    prd.CodPackaging = InputProduct.CodPackaging;
    prd.CoefNetBrut = InputProduct.CoefNetBrut;
    index++;
    GetClientImpressionProductSel.Add(prd);
    }

    CalculateGrossWeight(ProdSelection);
    }


    You need to create a new instance of the object that you want to add to your list, otherwise it will add a reference to the same object and that is why you get the same values.






    share|improve this answer




























      1














      Try like this:



      List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
      int index = 1;
      GetClientImpressionProductSel.Clear();
      generateSeqNumber();

      foreach (var ProdSelection in ClientImpressionProdSelection)
      {
      for (index = 1; index <= InputProduct.NdPlettes;)
      {
      ClientImpressionProductSelectionM prd = new ClientImpressionProductSelectionM();
      prd.Sequence = Convert.ToInt32(GenResult);
      prd.Number = index;
      prd.ClientDestinataire = InputProduct.ClientDestinataire;
      prd.LieuDeLivraison = InputProduct.LieuDeLivraison;
      prd.CodeProduitClient = InputProduct.CodeProduitClient;
      prd.CodeCouleurClient = InputProduct.CodeCouleurClient;
      prd.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
      prd.AQP = InputProduct.AQP;
      prd.Produit = InputProduct.Produit;
      prd.RefFournisseur = InputProduct.RefFournisseur;
      prd.NdShipment = InputProduct.NdShipment.Value;
      prd.NdLot = InputProduct.NdLot;
      prd.Cdate = InputProduct.Cdate;
      prd.PoidsNet = InputProduct.PoidsNet;
      prd.PoidsBrut = InputProduct.PoidsBrut;
      prd.NbrPallet = InputProduct.NdPlettes.Value;
      prd.Material = InputProduct.Material;
      prd.CodClient = InputProduct.CodClient;
      prd.CodPackaging = InputProduct.CodPackaging;
      prd.CoefNetBrut = InputProduct.CoefNetBrut;
      index++;
      GetClientImpressionProductSel.Add(prd);
      }

      CalculateGrossWeight(ProdSelection);
      }


      You need to create a new instance of the object that you want to add to your list, otherwise it will add a reference to the same object and that is why you get the same values.






      share|improve this answer


























        1












        1








        1







        Try like this:



        List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
        int index = 1;
        GetClientImpressionProductSel.Clear();
        generateSeqNumber();

        foreach (var ProdSelection in ClientImpressionProdSelection)
        {
        for (index = 1; index <= InputProduct.NdPlettes;)
        {
        ClientImpressionProductSelectionM prd = new ClientImpressionProductSelectionM();
        prd.Sequence = Convert.ToInt32(GenResult);
        prd.Number = index;
        prd.ClientDestinataire = InputProduct.ClientDestinataire;
        prd.LieuDeLivraison = InputProduct.LieuDeLivraison;
        prd.CodeProduitClient = InputProduct.CodeProduitClient;
        prd.CodeCouleurClient = InputProduct.CodeCouleurClient;
        prd.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
        prd.AQP = InputProduct.AQP;
        prd.Produit = InputProduct.Produit;
        prd.RefFournisseur = InputProduct.RefFournisseur;
        prd.NdShipment = InputProduct.NdShipment.Value;
        prd.NdLot = InputProduct.NdLot;
        prd.Cdate = InputProduct.Cdate;
        prd.PoidsNet = InputProduct.PoidsNet;
        prd.PoidsBrut = InputProduct.PoidsBrut;
        prd.NbrPallet = InputProduct.NdPlettes.Value;
        prd.Material = InputProduct.Material;
        prd.CodClient = InputProduct.CodClient;
        prd.CodPackaging = InputProduct.CodPackaging;
        prd.CoefNetBrut = InputProduct.CoefNetBrut;
        index++;
        GetClientImpressionProductSel.Add(prd);
        }

        CalculateGrossWeight(ProdSelection);
        }


        You need to create a new instance of the object that you want to add to your list, otherwise it will add a reference to the same object and that is why you get the same values.






        share|improve this answer













        Try like this:



        List<ClientImpressionProductSelectionM> ClientImpressionProdSelection = _customerPrintService.GetClientImpressionProductSelection().ToList();
        int index = 1;
        GetClientImpressionProductSel.Clear();
        generateSeqNumber();

        foreach (var ProdSelection in ClientImpressionProdSelection)
        {
        for (index = 1; index <= InputProduct.NdPlettes;)
        {
        ClientImpressionProductSelectionM prd = new ClientImpressionProductSelectionM();
        prd.Sequence = Convert.ToInt32(GenResult);
        prd.Number = index;
        prd.ClientDestinataire = InputProduct.ClientDestinataire;
        prd.LieuDeLivraison = InputProduct.LieuDeLivraison;
        prd.CodeProduitClient = InputProduct.CodeProduitClient;
        prd.CodeCouleurClient = InputProduct.CodeCouleurClient;
        prd.CodeFournisseurEMPourClient = InputProduct.CodeFournisseurEMPourClient;
        prd.AQP = InputProduct.AQP;
        prd.Produit = InputProduct.Produit;
        prd.RefFournisseur = InputProduct.RefFournisseur;
        prd.NdShipment = InputProduct.NdShipment.Value;
        prd.NdLot = InputProduct.NdLot;
        prd.Cdate = InputProduct.Cdate;
        prd.PoidsNet = InputProduct.PoidsNet;
        prd.PoidsBrut = InputProduct.PoidsBrut;
        prd.NbrPallet = InputProduct.NdPlettes.Value;
        prd.Material = InputProduct.Material;
        prd.CodClient = InputProduct.CodClient;
        prd.CodPackaging = InputProduct.CodPackaging;
        prd.CoefNetBrut = InputProduct.CoefNetBrut;
        index++;
        GetClientImpressionProductSel.Add(prd);
        }

        CalculateGrossWeight(ProdSelection);
        }


        You need to create a new instance of the object that you want to add to your list, otherwise it will add a reference to the same object and that is why you get the same values.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 6:55









        Sergiu MuresanSergiu Muresan

        3346




        3346






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387569%2funable-to-display-incremented-value-in-a-list-in-c-sharp%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini