Results 1 to 9 of 9

Thread: [2005] Datagridview question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    [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:
    1. Private Sub DGFormTypes_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGFormTypes.CellLeave
    2.         Try
    3.             If Me.DGFormTypes.RowCount > 0 Then
    4.                 If DGFormTypes.CurrentCell.ColumnIndex = 1 Then
    5.                     PopulateDGV()
    6.                 End If
    7.             End If
    8.         Catch ex As Exception
    9.             Debug.WriteLine(ex.Message)
    10.         End Try
    11.     End Sub

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    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

  4. #4
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Re: [2005] Datagridview question

    I am experiencing the same issue here. Does anyone know if this ever get resolved?

    Thanks

  5. #5
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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

  6. #6
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    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...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    156

    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:
    1. Private Sub DGFormTypes_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGFormTypes.CellContentClick
    2.         If DGFormTypes.CurrentCell.ColumnIndex = 1 Then
    3.             DGFormTypes.CurrentCell = DGFormTypes.Item(DGFormTypes.CurrentCell.ColumnIndex - 1, DGFormTypes.CurrentCell.RowIndex)
    4.         End If
    5.     End Sub
    6.  
    7.     Private Sub DGFormTypes_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGFormTypes.CellValueChanged
    8.         Try
    9.             If Me.DGFormTypes.RowCount > 0 Then
    10.                 If DGFormTypes.CurrentCell.ColumnIndex = 1 Then
    11.                     PopulateDGV(False)
    12.                 End If
    13.             End If
    14.         Catch ex As Exception
    15.             Debug.WriteLine(ex.Message)
    16.         End Try
    17.     End Sub

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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:
    1. Private Sub DataGridView1_CellMouseUp(ByVal sender As Object, _
    2.                 ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) _
    3.                 Handles DataGridView1.CellMouseUp
    4.  
    5.         If TypeOf DataGridView1.CurrentCell Is DataGridViewCheckBoxCell Then
    6.             DataGridView1.EndEdit()
    7.             Dim cellVal As Boolean = DirectCast(DataGridView1.CurrentCell.Value, Boolean)
    8.             If cellVal Then
    9.                 MsgBox("Current cell is Checked")
    10.             Else
    11.                 MsgBox("Current cell is Unchecked")
    12.             End If
    13.         End If
    14.     End Sub

  9. #9
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    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
  •  



Click Here to Expand Forum to Full Width