Results 1 to 4 of 4

Thread: [RESOLVED] how to call event if data grid view is hidden

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Resolved [RESOLVED] how to call event if data grid view is hidden

    Hi All,

    I want to add function on my program, because now if my table is empty i hide the datagridview.
    so if it is hidden or not hidden i want to do an action also.

    what is the expression should i use to get what i want ?



    i try .hide but its throwing an error. expression does not produce a value.


    Code:
      Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
           If dgvCell1_Muscatel_MPCA.Hide = False Then
                    dgvCell1_Muscatel_MPCA.DataSource.clear()
                    LoadAll()
    else
    msgbox("DAta grid view is hidden")
                End If
        End Sub

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: how to call event if data grid view is hidden

    That's because .Hide is a method... not a property. The property you're looking for .Visible... that's the property that indicates if a control is visible or not.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: how to call event if data grid view is hidden

    First of all, you're not calling an event. Events are not called, so the concept makes no sense. You call methods. You get and set properties. You raise events.

    The thing is, you're not even talking about raising an event. Your question has pretty much nothing to do with events at all. Like all controls, the DataGridView has the members that relate to visibility: the Show and Hide methods and the Visible property. If you want the control to be visible then you either call Show or you set Visible to True. If you want the control to NOT be visible then you call Hide or you set Visible to False. If you want to know whether the control is currently visible or not then you get the Visible property. It's that last that you want to do, so you should be getting the Visible property.

    If you want to do something only if the control is visible then you can do this:
    vb.net Code:
    1. If dgvCell1_Muscatel_MPCA.Visible = True Then
    but it's more correct to do this:
    vb.net Code:
    1. If dgvCell1_Muscatel_MPCA.Visible Then
    The Visible property is itself a Boolean so there's no point comparing that to another Boolean to get a third Boolean that will always have the same value as the original anyway.

    If you want to do something only if the control is NOT visible then you can do this:
    vb.net Code:
    1. If dgvCell1_Muscatel_MPCA.Visible = False Then
    but it's more correct to do this:
    vb.net Code:
    1. If Not dgvCell1_Muscatel_MPCA.Visible Then

    As a general rule, if you're writing an If...Else block then you should always test for the positive case explicitly and let the Else handle the negative case. If you always do that then you can't accidentally put your blocks the wrong way around. In your case, the code should be:
    vb.net Code:
    1. If dgvCell1_Muscatel_MPCA.Visible Then
    2.     '...
    3. Else
    4.     '...
    5. End If

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    90

    Re: how to call event if data grid view is hidden

    Thanks Sir JM,
    very clear explanation ..

Tags for this Thread

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