Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trapping DateGrid events

Posted on 2004-11-02
9
Medium Priority
?
213 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
Comment
Question by:azrakdragon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 300 total points
ID: 12470889
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
ID: 12470900
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 300 total points
ID: 12470918
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12470964
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
ID: 12471071
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
ID: 12471079
The above happens when the user uses the arrow keys
0
 

Author Comment

by:azrakdragon
ID: 12471144
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
ID: 12471148
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
ID: 12471237
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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