|
-
Sep 21st, 2006, 02:24 PM
#1
Thread Starter
Addicted Member
[2005] Datagridview question
hi,
I have a DGV control on my form that is populated with 2 columns (one is just a text column and the other is a checkbox column)
What I am trying to do is invoke a procedure when an action is performed on any given checkbox in the DGV.
The problem is that I am checking which row was changed and I am having troubles finding the DGV event that happens AFTER the checkbox state has changed.
sofar I tried CELLLEAVE,CELLCLICK,CELLENDEDIT etc. to no avail
so the question is which EVENT happens AFTER the content of the cell has been modified?
thanx
Below is an example which did NOT work
VB Code:
Private Sub DGFormTypes_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGFormTypes.CellLeave
Try
If Me.DGFormTypes.RowCount > 0 Then
If DGFormTypes.CurrentCell.ColumnIndex = 1 Then
PopulateDGV()
End If
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
-
Sep 21st, 2006, 03:01 PM
#2
Re: [2005] Datagridview question
did you try the CellValueChanged event? It will fire when you leave a cell if the value in the cell has changed
-
Sep 21st, 2006, 03:08 PM
#3
Thread Starter
Addicted Member
Re: [2005] Datagridview question
yes, that one sort of works, but the problem is that if the focus is still on the cell that has been changed it wont fire. It only fires after you lose focus off the cell, but at that point it is too late for me
-
Dec 7th, 2006, 05:39 AM
#4
Hyperactive Member
Re: [2005] Datagridview question
I am experiencing the same issue here. Does anyone know if this ever get resolved?
Thanks
-
Dec 7th, 2006, 06:30 AM
#5
Fanatic Member
Re: [2005] Datagridview question
Hi, i dont have the answer to you're problem but if you want the event to fire while the cell is still in focus (if it is possible) then the event will fire as soon as the smallest change has been made. Is this what you want?
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Dec 7th, 2006, 07:32 AM
#6
Hyperactive Member
Re: [2005] Datagridview question
I have a checkbox column, and all I want to do is to detect when the the cell checked status changes.
I have tried using the cellclick event and the cellvaluechanged event but neither do what I wish.
The cellclick event fires ok but at that time the value of the cell hasn't been altered.
I can't assume that the existing value will just be toggled either as it is possible to click in the cell and miss the check box.
The cellvaluechanged event on the other hand looked more promising, but it only seems to fire when the cell is exited. Normally when another rows cell is clicked.
I assume this is something to do with the change not being commited but this is not a databoundcolumn, so I would have hoped that it would fire immediately.
I could of course change it to an image column and show a tick or cross whenenever the cell is clicked but this seems like something I shouldnt have to do...
-
Dec 7th, 2006, 09:26 AM
#7
Thread Starter
Addicted Member
Re: [2005] Datagridview question
well I did solve this problem, but I had to improvise... Not sure if this is a good way of doing things, but that's the only way I could make it work.... Anyway here is how this is supposed to work...
When a user clicks on a cell (NOT the content of the cell) I wrote the code that effectively changes the focus from that cell to a previous cell in the same row.
That way the CellValueChanged event fires like I wanted it to.
VB Code:
Private Sub DGFormTypes_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGFormTypes.CellContentClick
If DGFormTypes.CurrentCell.ColumnIndex = 1 Then
DGFormTypes.CurrentCell = DGFormTypes.Item(DGFormTypes.CurrentCell.ColumnIndex - 1, DGFormTypes.CurrentCell.RowIndex)
End If
End Sub
Private Sub DGFormTypes_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGFormTypes.CellValueChanged
Try
If Me.DGFormTypes.RowCount > 0 Then
If DGFormTypes.CurrentCell.ColumnIndex = 1 Then
PopulateDGV(False)
End If
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
-
Dec 7th, 2006, 09:27 AM
#8
Re: [2005] Datagridview question
I've been using this method on datagridviewcheckboxcolumns... The trick is, since it is a checkbox column, the cell's value is either checked or unchecked... So as soon as the user done click, which is essentially the MouseUp event, I call EndEdit on the datagridview, and read the current cell's value
VB Code:
Private Sub DataGridView1_CellMouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) _
Handles DataGridView1.CellMouseUp
If TypeOf DataGridView1.CurrentCell Is DataGridViewCheckBoxCell Then
DataGridView1.EndEdit()
Dim cellVal As Boolean = DirectCast(DataGridView1.CurrentCell.Value, Boolean)
If cellVal Then
MsgBox("Current cell is Checked")
Else
MsgBox("Current cell is Unchecked")
End If
End If
End Sub
-
Dec 8th, 2006, 05:24 AM
#9
Hyperactive Member
Re: [2005] Datagridview question
Thanks guys. Both options make sense. Both have the feel of being a little friggy - but if it works it works.
I appreciate the help.
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
|