Windows Forms Control - Huge list of filenames - c#

Which control would be best for showing a huge (300.000+) list of filenames?
I've tried DataGridView, but it seems to be overkill and also slow.
Are there better alternatives?

None.
No USER will be able to handle a single list of 300.000+ entries in a meaningful way. Looks like your design is seriously flawed - do you really have to present the complete list?
Consider using a search box and let the users search the file names (use auto completion/suggestions like Google et.al.) or create a separate list for every starting letter (like most address books do). Or find another way to reduce the number of entries from which the user has to select.

The standard ListView control has a virtual mode designed specifically for your situation. I've used it with a million row list previously and it does the job well.
It is a true virtual mode. In other words memory allocation and list population time remains low regardless of the size of the overall list. This is unlike the DataGridView that really starts to slowdown and use memory on large lists.
To use virtual mode set:
VirtualListMode = true
VirtualListSize= 300000
(or whatever size your list currently is)
Then handle the RetrieveVirtualItem event to populate the list on demand from your list. You may also wnat/need to handle the CacheVirtualItems and SearchForVirtualItem events.

Set up pagination and restrict the number of rows displayed by the DataGrid. You can add a combobox to jump between pages. This is a standard solution.
also see this post https://stackoverflow.com/questions/2125963/need-help-in-gridview-and-table

Have you tried the ListView with report style? This is the control used by Windows natively in its file browsers.

Following on from gotch4's answer. Here is a good article from CodeProject on how to do paging with a DataGridView.

You might want to check out ObjectListView, specifically the VirtualObjectListView:
http://objectlistview.sourceforge.net/cs/index.html
I forget off hand what license it has been released under so you might want to look at that before using it in a commercial application.

Related

Is there really a need to use CacheVirtualItems on a virtual ListView if ListViewItems are fixed and already on a List<T>?

I am wondering what the actual design purpose of the CacheVirtualItems event is for when using a ListView in virtualmode. So far most of the examples I can find online are for purposes like when clicking Next on a list of data in an online page and what not.
If I have a fixed List of ListViewItems that are loaded manually by the user and the items will always be kept in the collection no matter what, should I even be using the cache event at all? It's not like I will be generating new ListViewItems per scroll. Should I be fine design pattern-wise without handling the event on a fixed collection of ListViewItems?
No, if you are holding the entire list in memory then there is no need to respond to CacheVirtualItems. It is merely a hint that you can use to improve efficiency.
The CacheVirtualItemsEventArgs argument supplies an index range, allowing you to efficiently load just that range into memory in a single operation. This avoids having either to load the entire list or to load individual items one at a time.

massive string array (40000) elements in listbox

I know this is a stupid question, I need to let you guys know that I am fully aware that it is useless in 99% of situations to make a listbox with this many elements in c#:
That being said I need this to be done...is there any way to populate a listbox with 40000 elements without it completely destroying performance/freezing up, thanks!
note: I have tried it, this is per the exact requirements of a professor...when adding 40000 elements through a DataSource and DataBind the application freezes up
You tell me.
for(i=0;i<40000;i++)
{
listBox1.Items.Add("click me");
}
Even if is possible (I never tried it), the usability for this form will be 0.
In that cases a more usable implementation is via lookup text-boxes and lists, where the user can enter a text to search record that matches this text and displays them in a any kind of list.
It is of course possible to do it, but not very practicable.
When using a desktop technology like WinForms or WPF, for a large number of items like this you are better off using something like an auto complete textbox, and have it set to filter/search after the user has typed two or three characters. In this case you can also use a control that offers scrolling virtualisation - this means that there is only a limited number of UI elements created in the scrolling portion of the dropdown, and those elements get reused when a scroll occurs. If you don't use virtualisation then a new element gets created for every list item that gets scrolled in to view. (Note that Silverlight controls have this functionality - just in case it's an option).
For ASP.NET though I would suggest that you do not want to do anything that would cause a large transfer of data (large items, or small items but lots of them) as it won't be performant. Instead you should look to do what Google does - retrieve search results in a paged fashion.

Text user control with sorting possibility

I need control in winforms that can add tens lines per second. I use now richtextbox, but i'm looking for something with sorting possibility (according some datatime or int)
Lines which are added are just custom objects complex of several int and datetime.
Delay aspect is quite important here.
EDIT:
It can be also some table/grid, but I suppose it take too much time (searching existing lines and inserting new line into appropriate place)
RichTextBox will typically offer more overhead in managing, searching, and inserting.
Much more appropriate would be a control like ListView. It gives simpler control over sorting, scrolling, and more.
Additionally, ListView has the ability to handle Virtual data backing. If performance or content size is an issue, this will let you only worry about the sub-set currently displayed in the ListView "view" window.
Two options
Use RichTextBox as you are doing now hold the data in a structure like SortedList from which the control will be updated.
Or, you can use a Grid, format the look and feel of the grid to remove the row & column grid lines and each new line will get appended this way you can let user sort by clicking on the header...
As for adding say ten lines per second I am pretty certain both these controls can handle more traffic than that....

making listView acting like treeView in winforms

is there any way to make winforms listView showing data like treeView. i mean to make it verticaly oriented and to show columnHeaders one under another and not to put them in horizontal line?
thanx for assistance
Consider using this open-source ObjectListView.
It's a mature control that can show all sorts of lists, a tree-list and much much more (not my code - I'm just a happy user).
It take a few minutes to get used to the idea of using it, but once you got it - using it is a breeze.
Examples:
You can also consider using Better ListView. The usage is 99% same as the original .NET ListView, but it has many extras. For example, every item has a ChildItems property in which you can put further children.

a loading screen for a c# wpf listbox

I'm using a list box where there are on average about 500 thumbnails (items) that can be sorted and searched.
Since I'm using default databinding and search descriptors (which I've heard are slow due to reflection) the list takes a noticeable pause of a few seconds loading, sorting, and searching (the list dynamically updates based on the contents of the search box so the first one or two letters typed are really slow).
I don't think I can fully do away with reflection give the timeframe for the project, and speed isn't super essential, but I'd like some kind of graphical indication of the delay so it doesn't confuse the user. How could I do something like a website video loading screen where the listbox grays out and some kind of loading circle indicates it's processing until the list is ready? Or even just grayed out with the words "Loading..." for a few seconds could work. Any ideas?
Thanks in advance for your help and suggestions!!!
Silverlight-Controlkit comes with a very handy "busyindicator"-control... too bad there seems to be no such thing for WPF by default.
But I found this seemfully comparable control for you:
http://sweux.com/blogs/pombeiro/index.php/2009/12/01/a-busy-state-indicator-attached-behavior/
download-source:
http://gallery.expression.microsoft.com/en-us/BusyIndicator
Like Veer wrote, BackgroundWorker is probably your best bet.
For the graphical indication of progress and/or delay, take a look at
http://www.codeproject.com/KB/WPF/WPF_Loading_Wait_Adorner.aspx
It looks like pretty much exactly what you want to do.
Try BackgroundWorker
Use the DoWork method to update your list dynamically based on the search keyword
Use the ProgressChanged method to update your UI with some animation saying 'Loading'. A ProgressBar could be used
Use Dispatcher to access your list inside the DoWork method

Categories