none
Modify list config content RRS feed

  • Question

  • I try to modify content of configList

    I set  configList as

    public static List<string> configList = new List<string>();//I set it static because other class will use it

     configList  will look like

    A=CTP//configList [0] B=115200//configList [1] C=8//configList [2] D=N//configList [3] E=1//configList [4] F=0//configList [5] G=//configList [6] [DATA]//configList [7] <P

    //Dynamicly add items </ <F0 <I0 <R1 <R2 <R3 </ <F1 <I0 <I1 </ <F2 </

    From  configList [0] to configList [7] I can just call configList [i] to modify it

    but after configList [7]

    <p//star 

    contents

    <///end

    content may one item also may one hundred items those are user define how may content inside

    If I try to modify content inside how to do those?

    Maybe I want clear content then add new content inside.

    Thanks

    Friday, September 27, 2019 7:05 AM

Answers

  • Hi CY_Chen,

    Thanks for the feedback.

    >>I want to clear all items after start index 8 but I can not confirm end index because my <p and <F are all dynamicly grow. I can't confirm end index.

    You could use List<T>.LastIndexOf Method to do it. Here is my sample of code.

    for (int i = 0; i < 8; i++)
                {
                    configList.Add(i.ToString());
                }
                for (int i = 0; i < 3; i++)
                {
                    configList.Add("<F" + i);
                    for (int j = 1; j <= 2; j++)
                    {
                        configList.Add("<I" + j + "," + "Image,");
                    }
                    configList.Add("</");
                }
             
                int index = configList.LastIndexOf("</");
                configList.RemoveRange(8, index - 7);
    

    I have tested it, which could clear all items after start index 8.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CY_Chen Monday, September 30, 2019 8:46 AM
    Monday, September 30, 2019 7:48 AM
    Moderator

All replies

  • Hi CY_Chen,

    Thank you for posting here.

    //Dynamicly add items
    </
    <F0
    <I0
    <R1
    <R2
    <R3
    </
    <F1
    <I0
    <I1
    </
    <F2
    </

    I want to know if these items has some regulation or these items are random.

    I think it is the best way for you to give a example to let me solve your problem better.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 27, 2019 8:19 AM
    Moderator
  • Hi Jack

    Thanks for answering

    I provide my dynamicly content structure

            public static void Save()
            {
                for (int i = 0; i < TabItemCount;i++)
                    {
                        configList.Add("<F" + i);
                        for (int j = 1; j <= Item[i].Items.Count; j++)
                        {
                            configList.Add("<I" + j  + "," + "Image,");
                           
                            //k++;

                        }//end inner for loop
                        configList.Add("</");
                    }//end outer for loop
    }

    Outer for loop is my TabControl contain TabItems//TabItems are dynamicly add

    configList.Add("<I" + j  + "," + "Image,");//also dynamicly add

    I want to modify those configList dynamicly add content

    old strcture was Three TabItems (F0 F1 F2)

    F0 contains  I0 I1 I2 I3
    F1 contains  I0 I1
    F2 contains  Nothing
    <F0
    <I0
    <I1
    <I2
    <I3
    </
    <F1
    <I0
    <I1
    </
    <F2
    </

    My problem was if I already call Save() function

    My structure TabControl add new TabItems and each TabItem content add new image

    Then call Save() function 

    How to modify configList old dynamicly add content or update old one ?

    Thanks

    Friday, September 27, 2019 9:09 AM
  • It seems to me you need to save a copy of the original configList, then in the Save function create a new list that starts with members from the original and adds from your tab items.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Friday, September 27, 2019 5:06 PM
  • Hi Tim

    Thanks for answering

    It look difficult for me  I prefer clear item after configList [7] all configList [0] to configList [7] is static

    RemoveRange(Int32, Int32) is this method can support configList.RemoveRange(8);

    I want to clear all items after start index 8 but I can not confirm end index because my <p and <F are all dynamicly grow. I can't confirm end index.

    Thanks 

    Monday, September 30, 2019 6:27 AM
  • Hi CY_Chen,

    Thanks for the feedback.

    >>I want to clear all items after start index 8 but I can not confirm end index because my <p and <F are all dynamicly grow. I can't confirm end index.

    You could use List<T>.LastIndexOf Method to do it. Here is my sample of code.

    for (int i = 0; i < 8; i++)
                {
                    configList.Add(i.ToString());
                }
                for (int i = 0; i < 3; i++)
                {
                    configList.Add("<F" + i);
                    for (int j = 1; j <= 2; j++)
                    {
                        configList.Add("<I" + j + "," + "Image,");
                    }
                    configList.Add("</");
                }
             
                int index = configList.LastIndexOf("</");
                configList.RemoveRange(8, index - 7);
    

    I have tested it, which could clear all items after start index 8.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CY_Chen Monday, September 30, 2019 8:46 AM
    Monday, September 30, 2019 7:48 AM
    Moderator