-
Jul 15th, 2018, 09:10 PM
#1
Thread Starter
Lively Member
[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
-
Jul 15th, 2018, 09:18 PM
#2
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
-
Jul 15th, 2018, 09:22 PM
#3
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:
If dgvCell1_Muscatel_MPCA.Visible = True Then
but it's more correct to do this:
vb.net Code:
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:
If dgvCell1_Muscatel_MPCA.Visible = False Then
but it's more correct to do this:
vb.net Code:
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:
If dgvCell1_Muscatel_MPCA.Visible Then '... Else '... End If
-
Jul 15th, 2018, 10:08 PM
#4
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|