showing iteration through a DataGridView, updating the display/redraw - vb.net

I have a DataGridView with a single column that currently displays a short list of items. When the user clicks a button to run an update, each row/cell is read and processing begins.
I would like to have the selection indicator move down the rows in the DataGridView as it completes processing of each record. How can I display the iteration of the DataGridView rows while the processing is underway? A redraw of the DataGridView or something.
This is a VB.net windows form, I know how to do this with AJAX I think, but how can I achieve this in a Windows form?
Thanks,

For each row As DataGridViewRow in myDataGridView.Rows
'Unselect previous row, then select current row
myDataGridView.ClearSelection()
row.Selected = True
myDataGridView.Refresh()
'Do processing here...
Next
This will select each row but won't scroll down if the current row is out of view. To scroll down automatically you can set the DataGridView FirstDisplayedScrollingRowIndex property.

Related

Prevent focus change to next row in Datagridview with checkbox

I have created a datagridview and added a checkbox in 1st column.
Fullrowselected = true
Now on Enter key press, the row focus changes to next row.
Is there some property setting to change?
How can I prevent this change in row focus?

Button doesn't work after DataGridView Validating Event

I have a Form with a TabControl on it. On one of the TabPages is a DataGridView with a New- and Delete-Button below it. I also have a Validating-Event for the DataGridView. Inside the Event I do some checking. If the conditions are not met I do a simple:
e.Cancel = True
Return
But after that my Delete-Button isn't working anymore. Even if I set a Breakpoint right at the start of the Click-Event nothing is happening what could that be? I have set the CausesValidation to false on the Button.
Update
I need to handle both Events, because the Sum of this DataGridView is compared to another value. The Sum can't be smaller or bigger than the other Value. But the User can enter what he wants as long as at the End the Sum is correct. I can't do that in the CellValidating because as soon as I change a Value the Sum doesn't match anymore
Update
I have observerd the following Scenarios where it doesn't work:
I change Data in the DataGridView and then trigger the Validating-Event. It starts working again when I input correct Data and switch Tabs
I create a new Row, trigger the CellValidating-Event and after that the DGV Validating-Event

Rows Not Highlighting in Data Grid View

I have a simple selection form that displays a DataGridView and allows the user to select a record to process. I have a short sub routine that loops through the DGV and highlights rows based on a date comparison with a dictionary when the form loads. This works great the first time I open the form, but on subsequent form opens, the grid doesn't highlight. When I step through the code it looks like the rows should be highlighted, but when the form displays, nothing is highlighted.
Here is the code I'm using. I cannot figure out why it doesn't always work. Is there a better, more reliable way to accomplish this?
For Each row As DataGridViewRow In dgvPending.Rows
For Each pair In dPending
If row.Cells.Item("ID").Value = pair.Key Then
If row.Cells.Item("LAST_UPDATED").Value > pair.Value Then
row.DefaultCellStyle.BackColor = Color.BlanchedAlmond
End If
End If
Next
Next

Detect when user has finished editing a cell in a datagridview

I am using DataGridView1.CellEndEdit to detect when the user finishes to edit a cell.
In my program i am doing this:
Filling a Datagridview with a binding source
Filtering with the bindingsource filter
order by the first column alphabetically
edit a cell
Write edited values in the database
The problem is: When I finish CellEndEdit is fired and the cell does this:
write new values to Datagridview
Refresh row order based on the new value of the cell and update the bindingsource filter
Fire CellEndEdit
For me this is a problem because I need to read the content of every cell of the row, in order to update the database and once it gets the new values it is moved to a unknown position OR hidden because it does not meet the filter criteria anymore and thus if I read the row it was before I get the values of a row that has nothing to do with the one I am looking for.
Is there a way to get the values of the entire row containing the cell i just edited from within the CellEndEdit sub?
Solved by adding a KeyUp event handler and storing each cell of the row in a variable on every keyup event.
The CellEndEdit event provides DataGridViewCellEventArgs arguments which contains the RowIndex.

figure out rowindex on a row I just inserted?

I've got a vb project I am updating and it has a datagridview, a panel, and buttons along the bottom. The buttons control CRUD operations. The panel shows numerical up/downs and textboxes to represent the selected row.
I use some logic to keep track of current selected row and current row index for timer updates in the background. Upon delete I reset focus on the first row. Upon loading I set focus on first row. On update I keep current row focus.
Upon a good insert I would like to set the focus to the row I just inserted. But I do not know a way to determine what the rowindex value is for this freshly inserted row. My datatable which the datagridview uses is sorted on two id columns so it's not like the new entry will just jump to the bottom.
Any ideas on how I can implement this?
If you don't want to deal with the RowAdded event as Jay Riggs suggested, if you add it using a row object, as opposed to just Rows.Add, you should be able to pull that off of the row object after it's inserted.
Dim dgr As New DataGridViewRow()
DataGridView1.Rows.Add(dgr)
Me.DataGridView1.Rows.IndexOf(dgr)
This should also work for insert as well.
Check out the DataGridView RowAdded event; its DataGridViewRowsAddedEventArgs parameter includes the RowIndex property which gives you what you need.
The event fires everytime a row is added, so you'll have to either wire the event up when you want to check for added rows, or ignore the event when you don't care when a row is added (such as when your grid fills with data).
If you manually add rows to the DataGridView, then you can just use the return value from the Add method. Examples:
Dim newRowIndex As Integer = myDataGridView.Rows.Add()
myDataGridView.Rows(newRowIndex).Selected = True
No need to call IndexOf. If the DataGridView is bound to a DataSource then Jay Riggs' solution of using the RowsAdded event is the way to go.