Results 1 to 6 of 6

Thread: DataGridView sometimes won't delete

  1. #1

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

    DataGridView sometimes won't delete

    I have a form on which I swap out a datagridview and a panel. There is a button on the form for this. This is for reporting some data. It works except when you perform a certain sequence of events and then click the swap button while the dgv is showing to switch to the panel, the dgv won't delete. Why wouldn't a datagridview delete? This code definitely works much of the time. And in the case where the dgv does not go away, I checked and the code is definitely being executed.

    Code:
    ReportDataGridView.Dispose()
    ReportDataGridView = Nothing
    Any ideas or anything I could do to troubleshoot this?

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,517

    Re: DataGridView sometimes won't delete

    Quote Originally Posted by projecttoday View Post
    I have a form on which I swap out a datagridview and a panel. There is a button on the form for this. This is for reporting some data. It works except when you perform a certain sequence of events and then click the swap button while the dgv is showing to switch to the panel, the dgv won't delete. Why wouldn't a datagridview delete? This code definitely works much of the time. And in the case where the dgv does not go away, I checked and the code is definitely being executed.

    Code:
    ReportDataGridView.Dispose()
    ReportDataGridView = Nothing
    Any ideas or anything I could do to troubleshoot this?
    What is the sequence of events that make the dgv not delete. Also, you need to post all the relevant code, not just 2 lines. The more information you provide, the better.

  3. #3

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

    Re: DataGridView sometimes won't delete

    I have found a working solution, although I don’t know why it works and the other way doesn’t.

    If you’re interested: Does NOT work:

    Code:
    Private Sub ReportViewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewButton.Click
    
    If ReportView = "Scroll" Then
    ReportView = "Page"
    If Not IsNothing(ReportDataGridView) Then
    ReportDataGridView.Dispose()    <---------------------------- this is the delete that doesn't work
    ReportDataGridView = Nothing
    End If
    If Not IsNothing(SortLabel) Then
    SortLabel.Dispose()
    SortLabel = Nothing
    End If
    
    NumRecsPerPage = 13
    PanelWidth = 972
    DisplayButtons()
    ReadData()
    PagN = 1
    DisplayPage(PagN, dt, PanelWidth)  ----------------------- puts a panel on the form
    ReportViewButton.Text = "Scroll View"
    ElseIf ReportView = "Page" Then
    ReportView = "Scroll"
    If Not IsNothing(ReportPanel) Then
    ReportPanel.Dispose()
    ReportPanel = Nothing
    End If
    If Not IsNothing(FooterPanel) Then
    FooterPanel.Dispose()
    FooterPanel = Nothing
    End If
    Scroll_View() --------------------------------------------------- puts a datagridview on the form
    ReportViewButton.Text = "Page View"
    End If
    End Sub
    This WORKS:

    Code:
    Private Sub ReportViewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewButton.Click
    
    If Not IsNothing(ReportDataGridView) Then
                ReportDataGridView.Dispose()
                ReportDataGridView = Nothing
    End If
    If Not IsNothing(SortLabel) Then
                SortLabel.Dispose()
                SortLabel = Nothing
    End If
    If Not IsNothing(ReportPanel) Then
                ReportPanel.Dispose()
                ReportPanel = Nothing
    End If
    If Not IsNothing(FooterPanel) Then
                FooterPanel.Dispose()
                FooterPanel = Nothing
    End If
    If ReportView = "Scroll" Then
                ReportView = "Page"
                NumRecsPerPage = 13
                PanelWidth = 972
                DisplayButtons()
                ReadData()
                PagN = 1
                DisplayPage(PagN, dt, PanelWidth)
                ReportViewButton.Text = "Scroll View"
    ElseIf ReportView = "Page" Then
                ReportView = "Scroll"
                Scroll_View()
                ReportViewButton.Text = "Page View"
    End If
    End Sub
    As you can see the deletions are done unconditionally (except to test if there’s something to delete) in the version that works.

    So I’ve got it working at least. I still don’t know why the divided deletes don’t work.

    This is the process. The first 4 steps work fine:

    Open the form in scroll (panel) view.
    Click on page (datagridview) view.
    Perform a search to filter the data.
    Click on scroll view.
    Click on page view. ------------ it executes but the scroll view (the datagridview) is still showing on top of the page view (the panel).

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataGridView sometimes won't delete

    I'm not sure why you would destroy the controls at all. Why not simply Hide and Show them or, if they have the same Location and Size, simply call BringToFront on the one you want to display and the other will be hidden behind it. That latter might cause issues with tab stops mind you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

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

    Re: DataGridView sometimes won't delete

    Working with controls on top of other controls in the designer would be difficult and there would have to be logic to hide/unhide controls on the last page. It's working fine now.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataGridView sometimes won't delete

    Quote Originally Posted by projecttoday View Post
    Working with controls on top of other controls in the designer would be difficult
    No, it wouldn't. There's nothing complex about it. You simply add the controls to the form and set the Location and Size for at least one of them in the Properties window. You now have two controls occupying the same space. You can work on the one you're looking at and if you want to work on the other, simply right-click the one in front and select Send To Back or you can use the Document Outline window. There's really nothing to it.
    Quote Originally Posted by projecttoday View Post
    there would have to be logic to hide/unhide controls on the last page.
    Huh? If you have a DataGridView and a Panel then you simply call Hide on one and Show on the other, or toggle their Visible properties. It's less complex than you have now.
    Quote Originally Posted by projecttoday View Post
    It's working fine now.
    If that was the case then you wouldn't be here.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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