If you have time consuming operations such as extensive mathematical calculations, file or database operations on a large amount of data, etc., then the GUI can go unresponsive until that operation is completed. Net Framework's solution to this problem is the Background Worker class.
Background Worker class executes the time consuming operation on a separate background thread thereby keeping the GUI responsive to the end user.
It can also report the progress of the operation periodically, cancel the operation while it is running and indicate when the operation is completed.
I allow the user to select a number of rows using the mouse and then click a button that says "check selected rows", which then cycles through the selected rows and sets a check box field in the datagrid (and thus the databound datatable) to checked/true. Value = True Next I then have a property / function I expose that should show me the number of currently checked rows. I have also tried updating the underlying datarow instead of the cell value, as in: For Each row In Data Grid.
It works like this: Dim cel As Data Grid View Check Box Cell For Each row In Data Grid. It looks like this: Public Read Only Property Checked Row Count() As Integer Get Dim v As Data View = New Data View(Data Table) v. Count End Get End Property When I select a set of rows and then click the button that runs the first set of code, the property represented by the second set is always ONE LESS than the number of rows selected.
It's like it's not automatically marking the last databound datarow as updated... I've tried programmatically changing the Current Cell property of the datagrid to another row, and this works, but it doesn't look good at all, and the user loses the cells they selected.
The time-consuming operation in this example is to import the contents of a CSV file to a data grid in VB.
First of all, Open Microsoft Visual Studio and create a new project of type Windows Forms Application Drag and drop the following controls to the form and set their properties as below using the Properties window The purpose of this program is to import the contents of a CSV file, perform a simple calculation and update the data onto a data grid view control.
The Form Load event (Form1_load) sets two key properties of the Backgroundworker control - Event of this sample program we use a Text Field Parser object to read the contents of a csv file line by line.The progress of this background operation is reported after each line is read.This is achieved by calling the Report Progress method of background worker object.In our program we have added some sleep after each line is read in order to simulate a time-consuming operation. The Private Sub bg Worker_Run Worker Completed(By Val sender As Object, By Val e As System. Run Worker Completed Event Args) Handles bg Worker. I have a Datagrid that is bound to a Datatable at runtime.