Solved

Trapping DateGrid events

Posted on 2004-11-02
209 Views
Last Modified: 2010-04-24
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.
0
Question by:azrakdragon
    9 Comments
     
    LVL 25

    Accepted Solution

    by:
    maybe look here (there is a vb example aswell)

    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q856q
    0
     
    LVL 25

    Expert Comment

    by:RonaldBiemans
    0
     
    LVL 19

    Assisted Solution

    by:arif_eqbal
    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
     
    LVL 19

    Expert Comment

    by:arif_eqbal
    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
     

    Author Comment

    by:azrakdragon
    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
     

    Author Comment

    by:azrakdragon
    The above happens when the user uses the arrow keys
    0
     

    Author Comment

    by:azrakdragon
    Thanks Ronald, Arif. With the links and code u guy's provided I have sorted my problem
    0
     
    LVL 19

    Expert Comment

    by:arif_eqbal
    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
     

    Author Comment

    by:azrakdragon
    Thanks
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    934 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now