0

I have a structure consisting of 7 different arrays with a size of 20000 each.
I want to show each array as an individual column in the ListView.
How do I add values column-wise in ListView such that a single column shows a single array? I have 7 columns in the ListView.
I'm fairly new to C#. I do know how to fill data row-wise, but I've come across column-wise filling for the first time.
Any kind of help appreciated.

2 Answers 2

1

Finally got the solution!!!

string[] temp = new string[10];
for (int i = 0; i < 20000; i++)
        {
            temp[0] = Array1[i].ToString();
            temp[1] = Array2[i].ToString();
            temp[2] = Array3[i].ToString();
            temp[3] = Array4[i].ToString();
            temp[4] = Array5[i].ToString();
            temp[5] = Array6[i].ToString();
            temp[6] = Array7[i].ToString();
            temp[7] = Array8[i].ToString();
            ListViewItem listItem = new ListViewItem(temp);
            MyListView.Items.Add(listItem);
        }
Sign up to request clarification or add additional context in comments.

1 Comment

@Ilya I. Margolin: Although this method is working, I would love to populate it faster since it takes about 2-3 seconds for the ListView to fill up. Would love to know if there is some way to speed it up without multi-threading
0

Assuming all arrays have exactly the same size, consider the following idea:

for (var i = 0; i < 20000; i++)
{ 
   AddRow(column1[i], column2[i], ...);
}

If it was a part of your question: no, list view doesn't support adding data column-wise. Neither do any native WPF or 3rd party controls I know of.

PERFORMANCE: As to performance of this solution it's not traversing 20k records that takes time, it's creating 20k wpf objects. Read up about wpf virtualization to address that.

Also keep in mind that you can easily spend weeks and months looking into faster controls and rendering technologies but what it is all ultimately boils down to is that user does not really need to see all 20k records on the screen. It is not humanly possible to comprehend such amount of information. Virtualization is just another technique to not load up stuff that user cannot see, but you could address the issue yourself, by say paging, or filters, or grouping.

WinForms: I just realized that you're not talking about WPF, you're probably talking about WinForms. There's no virtualization there, although you could probably find some 3rd party component that supports it. Consider paging then.

1 Comment

Thanks for all the help buddy.. I'm using WinForms and I would probably end up using some 3rd party component for speeding up the process.. Thanks again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.