Trapping DateGrid events

Is there a way to prevent navigation from one cell to another in a datagrid and to determine when u user has selected a different row in a datagrid? Not the cellchange event, but something similar to the rowcolchange event in vb6.
azrakdragonAsked:
Who is Participating?
 
RonaldBiemansCommented:
maybe look here (there is a vb example aswell)

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q856q
0
 
RonaldBiemansCommented:
0
 
arif_eqbalCommented:
No there's no direct way to get notified when the selected Row has changed

But you can find out using the CellChange Event only

Have a Form level variable LastRow
Dim LastRow as Integer=0

then

   Private Sub DetailsDataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsDataGrid.CurrentCellChanged
        If LastRow <> DetailsDataGrid.CurrentRowIndex Then
            LastRow = DetailsDataGrid.CurrentRowIndex
            DataGrid1_RowChanged()
        End If
    End Sub

    Private Sub DataGrid1_RowChanged()
        'Do Whatever You want
    End Sub

We just check in the CurrentCellChanged event whether the cell has changed within the Row or the Current Row has also changed if yes we call the function...You can even have an Event and raise it
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
arif_eqbalCommented:
And if you want to stop Navigation from one cell to another
Dim Cell as DataGridCell

    Private Sub DetailsDataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsDataGrid.CurrentCellChanged
        If LastRow <> DetailsDataGrid.CurrentRowIndex Then
            LastRow = DetailsDataGrid.CurrentRowIndex
            DataGrid1_RowChanged()
            Cell = DetailsDataGrid.CurrentCell()
        Else
            DetailsDataGrid.CurrentCell = Cell
        End If
    End Sub

here it will allow only Row wise navigation and notify when row chnages
0
 
azrakdragonAuthor Commented:
Hi Arif, thanks for the code. One more question: Now that cell navigation has been disabled, the first cell in the grid is still in 'edit' mode. It looks to the user that it can be updated. Is there a way to prevent this?
0
 
azrakdragonAuthor Commented:
The above happens when the user uses the arrow keys
0
 
azrakdragonAuthor Commented:
Thanks Ronald, Arif. With the links and code u guy's provided I have sorted my problem
0
 
arif_eqbalCommented:
Yeah Right
What you can do is set the Grid to readOnly just change the property in property window to readonly=true

It will still show the blue selection color so you can also set the SelectionBackColor same as BackColor so that it does not appear to be selected either

However there's another elegant method of disallowing changes to the cell

Trap the Underlying tables events like DataTable1_ColumnChanging Event

0
 
azrakdragonAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.