help with Listview...wont populate all columns

Ok I have a question regarding Listview

I have this function on form1 so that I can pass what is in the listview on form1 to form2

         // Populate the listbox configuration on the main screen
         foreach(ListViewItem CurrentItem in listviewConfig.Items )
         {                    
            string EntireRow = "";

            for (int i=0 ; i<CurrentItem.SubItems.Count ;i++)
            {
               EntireRow = EntireRow + CurrentItem.SubItems[i].Text + ", ";
               m_RootConList.Items.Add(EntireRow);
            }          
         }

Once I am at form 2  I have the same function to populate the second listview. Everything is currently going into the first column. How do I break it back out so it goes into the columns it is supposed to.

         foreach (ListViewItem item in rootConfig.Items)
         {
            string EntireRow = "";

            for (int i=0 ; i<item.SubItems.Count ;i++)
            {
               EntireRow = EntireRow + item.SubItems[i].Text + ", ";  
            }  
            listViewConn.Items.Add(EntireRow);
         }

here is an example of what I am getting in column 1.

The black cat ran across the street

what I need it to look like is

clolumn1                column2                  column3
The                       black                        cat ran across the street
LVL 2
NewMom2BrandonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravi SinghSenior Software EngineerCommented:
Hi, you could modify your existing foreach loop on form 2 to:

         foreach (ListViewItem item in rootConfig.Items)
         {
            string EntireRow = "";

            for (int i=0 ; i<item.SubItems.Count ;i++)
            {
               EntireRow = EntireRow + item.SubItems[i].Text + ", ";  
            }  
            listViewConn.Items.Add(new ListViewItem(EntireRow.Split(',')));
         }
NewMom2BrandonAuthor Commented:
That works for the first two but the problem is that the third column contains multiple items separated by a ","

So is there a way to only have the first two items split then add the rest to the last column as is.

I hope this makes sense

clolumn1                column2                  column3
The                       black                        cat, ran, across, the, street
Ravi SinghSenior Software EngineerCommented:
Hi, try:


         foreach (ListViewItem item in rootConfig.Items)
         {
            string EntireRow = "";

            for (int i=0 ; i<item.SubItems.Count ;i++)
            {
               EntireRow = EntireRow + item.SubItems[i].Text + ", ";  
            }  

            string[] newItemArray = EntireRow.Split(',');

            if (newItemArray.Length > 3)
            {
                string thirdColumnText = string.Empty;
            for (int i = 2; i < newItemArray.Length; i++)
                  thirdColumnText += newItemArray[i] + " ";

            listViewConn.Items.Add(new ListViewItem(new string[] { newItemArray[0], newItemArray[1], thirdColumnText } ));

            }
            else
            {
                    listViewConn.Items.Add(new ListViewItem(newItemArray)));
            }
         }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ravi SinghSenior Software EngineerCommented:
Sorry, the 'else' part should contain:

 listViewConn.Items.Add(new ListViewItem(newItemArray));

(it had an extra bracket at the end)
NewMom2BrandonAuthor Commented:
Thank you Very much!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.