|
-
May 13th, 2013, 07:30 AM
#1
Thread Starter
Addicted Member
Disable DGV row click unless if command is met
i am trying to work out how to not allow users to select a databound DGV row unless an if command is met
i know how to achieve this using CellClick i.e
Code:
Private Sub ProfilesDataGridView_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ProfilesDataGridView.CellClick
If NewActive = 0 Then
Try
Me.FilesTableAdapter.NewProfile(Me.FilesDataSet.Files, Prifle_NameTextBox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
Else
MsgBox("You need to save the current profile before you can navigate away.", MsgBoxStyle.Exclamation)
End If
End Sub
BUT the DGV still selects the row that the user clicked on How can i make it so when the user clicks on ok the DGV will return to the Row that was being edited before the user attempted to click a new row
i hope that makes sense
-
May 13th, 2013, 09:27 AM
#2
Re: Disable DGV row click unless if command is met
In order to return to the previously selected row, you somehow have to save what that row is first, right?
Try adding these lines (red) to your code:
Code:
Private lastSelectedCell As DataGridViewCell = Nothing
Private Sub ProfilesDataGridView_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ProfilesDataGridView.CellClick
If NewActive = 0 Then
Try
Me.FilesTableAdapter.NewProfile(Me.FilesDataSet.Files, Prifle_NameTextBox.Text)
lastSelectedCell = ProfilesDataGridView.CurrentCell
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
Else
ProfilesDataGridView.CurrentCell = lastSelectedCell
MsgBox("You need to save the current profile before you can navigate away.", MsgBoxStyle.Exclamation)
End If
End Sub
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
May 13th, 2013, 09:32 AM
#3
Re: Disable DGV row click unless if command is met
Ah, if wishes were horses ...
What exactly is the condition? Why do you need to prevent selection (isn't prevention of editing enough?)? What is the purpose of returning to a row where editing has, presumably, been completed (apart from annoying the user!)? And how on Earth is the code you've posted related to your supposed intent?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|