Results 1 to 14 of 14

Thread: [RESOLVED] Datagridview delayed row disappearance

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Resolved [RESOLVED] Datagridview delayed row disappearance

    I have a datagridview on my form. The datagridview has a bindingsource on a table in a dataset. I filter the datagridview on a boolean field:

    Code:
    tblTransactionsBindingSource.Filter = "Complete = False"
    If you click on Complete on the datagridview on one of the rows being displayed the row disappears. Well, almost. It disappears after you click on another row. What property do I need to set to cause it to disappear immediately? I tried EditOnEnter and that didn't work.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datagridview delayed row disappearance

    Quote Originally Posted by projecttoday View Post
    I have a datagridview on my form. The datagridview has a bindingsource on a table in a dataset. I filter the datagridview on a boolean field:

    Code:
    tblTransactionsBindingSource.Filter = "Complete = False"
    If you click on Complete on the datagridview on one of the rows being displayed the row disappears. Well, almost. It disappears after you click on another row. What property do I need to set to cause it to disappear immediately? I tried EditOnEnter and that didn't work.
    I actually demo'd that for you in another of your recent post.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview delayed row disappearance

    The demo doesn't work.

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datagridview delayed row disappearance

    Quote Originally Posted by projecttoday View Post
    The demo doesn't work.
    So what does not work? I am going to be blunt about this, I created the VS2008 project on a Vista machine at home and uploaded it to you then this morning at work downloaded the project I sent you and opened it in VS2010, ran it after conversion and it worked the same as when I created it in VS2008. Next I went one step farther and upgraded to Framework 4, built and ran the project which ran no different than the first version I gave you. So when you say it does not work a) that is extremely vague b) tells me you have not tried very hard to get it to work. With that said how do you expect others to assist you when you (from my view point) are not taking steps to learn from what is given to you.

    The attachment as mentioned above is the same other than converting to VS2010 via VS2010 upgrading, Framework 4 and a few lines where I broke lines down with no underscore. So again you have another working copy of the VS2008 project which shows the behavior you are questioning in regards to disappearing rows.
    Attached Files Attached Files

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

    Re: Datagridview delayed row disappearance

    You can handle the DataGridView.CellContentClick event and test the column of the cell to see if it's the "Complete" column. If it is, you set the datagridview.currentcell to nothing.
    Code:
     Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
            Dim colName As String = DataGridView1.Columns(e.ColumnIndex).HeaderText
            If colName = "Complete" Then
                DataGridView1.CurrentCell = Nothing
            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 -

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview delayed row disappearance

    kevininstructor, When the datagridview is filtered on false and you click Action on, then I want the row to disappear at that time instead of after one subsequent click. On your example the row does not disappear on click. Unless I'm doing something wrong.

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datagridview delayed row disappearance

    Quote Originally Posted by projecttoday View Post
    kevininstructor, When the datagridview is filtered on false and you click Action on, then I want the row to disappear at that time instead of after one subsequent click. On your example the row does not disappear on click. Unless I'm doing something wrong.
    My intent was to show you the behavior only not to make the row disappear as Stan has shown you. Why I was reacting to your second reply was that you said my project did not work which I interept as the project would not run. If you had said the project runs but give you results different than you were looking for then that is a whole different beast.

    So by applying Stan's method to my project as shown below, yes that gives you the results you want w/o checking the behavior checkbox.
    Code:
    Private Sub DataGridView1_CellContentClick( _
        ByVal sender As Object, _
        ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim colName As String = DataGridView1.Columns(e.ColumnIndex).HeaderText
    
        If TypeOf DataGridView1.Columns(e.ColumnIndex) Is DataGridViewLinkColumn AndAlso Not e.RowIndex = -1 Then
            Process.Start(DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value.ToString())
        ElseIf colName = "Action" Then
            DataGridView1.CurrentCell = Nothing
        End If
    End Sub

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview delayed row disappearance

    This appears to work:

    Code:
    Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged   
        BindingSource1.EndEdit()   
        DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)   
    End Sub
    stanav, Why would I want to set the cell to nothing?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview delayed row disappearance

    kevininstructor,

    Yes, originally I could not get the VB2008 project to open.

  10. #10
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datagridview delayed row disappearance

    Quote Originally Posted by projecttoday View Post
    kevininstructor,

    Yes, originally I could not get the VB2008 project to open.
    That is strange, I could open it on two different computers other than the computer used to create the project.

    Note I suffle between two xp and one vista box, none had issues opening the project. Perhaps it has something to do (if you are) with you using VS Express edition?

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

    Re: Datagridview delayed row disappearance

    Quote Originally Posted by projecttoday View Post
    This appears to work:

    Code:
    Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged   
        BindingSource1.EndEdit()   
        DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)   
    End Sub
    stanav, Why would I want to set the cell to nothing?
    Because when you click on a cell, it becomes the current cell. However, when the current row disappears as you want it to, the current cell is no longer valid. Setting it to Nothing forces the currentcellchanged event to be raised, which causes the datagridview to commit edit (the same effect you have when you click somewhere else out of the cell). Besides, it prevents the DGV to set another cell as the current cell on its own, which might or might not be what you want. When I go to a store to buy something, if that something suddenly becomes unavailable, I'd rather walk home empty handed than let the sales clerk stuffs something else into my bag as a replacement. That's just me
    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 -

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview delayed row disappearance

    I am using the Express edition.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview delayed row disappearance

    kevininstructor, I tried your amended code and that appears to be working. Thanks.

  14. #14
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datagridview delayed row disappearance

    Quote Originally Posted by projecttoday View Post
    kevininstructor, I tried your amended code and that appears to be working. Thanks.
    Your welcome.

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