How do you change DataGridView properties and values with threads in vb.NET? - vb.net

I have been beating my head against the wall for 2 weeks now, while trying to figure out a way to navigate through the rows of the DataGridView component with threads. I want to do this, because if the gridview is more than 300+ rows long the UI will hang up for about 30-60 seconds.
I am new to multi-threading, but I do know now the importance of thread safe applications and having to make sure that changes to UI components are done on the UI thread.
The steps i want to take are as follows(Unless someone has a better suggestion):
User selects an item in a ListBox
Disable UI interaction from the user
The datagridview is broken up into searchable ranges
search through each range in parallel and hide any rows that match the items that are selected in the listbox.
resume UI interaction to the user
Ultimately I want to beable to select multiple items in the listbox to hide or show them.
What I am looking for is someone to give me some idea as to where to start? Should I go with background worker, Task Parallel Library, custom threads, ect...?

Related

Exporting thousand lines from datagridview to excel using vb.net

Hi I'm currently having a datagridview with thousand (about 3000+) rows of record and 9 columns. I was using this method I found to export the datagridview to excel. There was no problem exporting hundred of rows but when it comes to thousand of rows, it hangs and it wouldn't respond to anything.
What problem could it be? and if there's any other way that is faster/better than this?
Thank you!
The code is being executed on the UI thread so of course your application would freeze while it's executing. If you want the UI to remain responsive then you'd have to execute the code on a secondary thread. The issue there is that the data is coming from a control, so that part at least must be executed on the UI thread.
I would suggest that one possibility is to use a BackgroundWorker and do the work in the DoWork event handler. You can set up a loop that calls ReportProgress, which raises the ProgressChanged event on the UI thread and allows you to get the data in pages, then write it out to your spreadsheet on the background thread. I'll follow up with an example.

An effective way to display multiple labels

I am looking for an effective, quick way to show multiple labels in a quick fashion. What's a good way to do this other than replacing all the .text properties of the labels one after another? It is my understanding that whenever you update a .text property the UI has to be repainted which will add to latency if you have 50+ controls to update.
I know threading is an option but when I tried this I didn't see much of a difference as I wasn't able to load 2 labels at once, I still had to wait for the UI thread before the labels would update. What other ways are there to effectively load 50+ labels quickly? The way it is now takes quite awhile(3-4s) and I feel this could be lowered. The information is being taken from a backend system so I don't have the option for datasets/etc.
You have to separate the code that retrieves the data from the database (which you do using a background thread) and the code that updates the UI (which should happen as quickly as possible because you don't want to block the UI for too long).
My suggestion would be to use the BackgroundWorker component to do retrieve the data for all 50 labels. When the BackgroundWorker raises the RunWorkerCompleted event you call the forms' SuspendLayout function, update all the values of the labels and then you call ResumeLayout. SuspendLayout stops a control from redrawing until you call ResumeLayout.
More info: BackgroundWorker, SuspendLayout, ResumeLayout

Generating about thousand or more controls with ExtJS

We have decided to use ExtJS for one of our large application's web-remake and we will have to generate screens/forms where we will have to render about thousand or more controls either in complete editable grid of in forms.
So may I know what is the best approach in doing so?
I have tried generating about thousand controls and it takes about more than 6 seconds on client-side and that too is going to be dependent on Client configuration about which I am positive that it will be at-least dual-core system most of the time.
But more than 6 seconds on localhost is like 10 seconds over the Internet so I am worried, I still have a choice of mixing normal html form/controls when there is high load but then it will miss the ExtJS touch (combo/number controls etc.), so any help or if you had similar experience do share.
Will XTemplate be faster in above case? I am still new to ExtJS so do share best practices if you know/used.
The best approach is not to do it this way. Creating thousands of controls will need huge amounts of memory, no matter how you do it. As you noticed, this makes an application extremely slow.
The solution is to keep the elements on the server and use some form of paging to create only the elements that the user can actually see.
Paging can be explicit ("Load next 10 rows") or implicit by firing an event when the scrollbar hits the right/bottom end and loading more rows.
Usually, you can even hide this from users. Always load a whole row (hiding elements in the same row which aren't visible because the browser window is too narrow usually doesn't help much).
On the server, you will know how many rows you have. Load the first 20 rows and display them. Find the height of the rows (ideally, they should be all the same height) and create an empty DIV below the 20 rows which expands the scrolled view. This makes it appear as if all the rows are there (user sees correct scrollbar which doesn't jump while scrolling).
As soon as that empty div comes into view, load more rows and shrink it.

App responsiveness during loop

I have designed an app in vb.net 2005 that at one point adds and loops over about 500k list in listbox about.
When adding these items to the listbox, the app freezes for about 5-10 minutes, then when looping over the items, processing them, the app also freezes for the same time. Am loading the data from a text file
How can I make my application
responsive during loops?
should I use a queue to process the
list?
what is the messagequeue control
for?
I recommend you to use BackgroundWorker. Store items in array, and bind listbox to it. Working with array will be much faster then with listbox'es collection.
Or you can call BeginUpdate/EndUpdate before/after adding new items.

limit selections in a listbox in vb.net

I am creating a web control in vb.net that contains a list box. I know that I am able to choose a selection mode of Single or Multiple, but I am interested in limiting a Multiple selection to a predetermined size. For example preventing a user from selecting more than 3 items.
I have tried adding a Validator to the list box, which might be a way forward, but was wondering if there was a way of changing the selection mode to something a bit different than just the two specified ones.
Any ideas or suggestions would be greatly appreciated
Edit: Unfortunately due to project limitations I am unable to use Javascript on this problem. very annoying I know!
You could try handling one of the SelectedIndexChange events. With multiple selection, each time this event fires you can check how many items have already been selected. If it is more than you want, have the handler deselect the one that was just selected. You could also put up a little red label under the listbox saying "Sorry, no more than [n] selections allowed."
EDIT:
Just noticed you said WEB. Same theory applies, but it would have to be done using Javascript.
On the SelectedIndexChanged event, write a short piece of code that will check the number of selected items and if it is greater than your desired amount, unselect the new selection (or unselect the oldest one, or however you wish this to operate).