emi_sastra
asked on
Prevent call a sub/function several times when data bind to gridview
Hi All,
I have a header and detail gridview.
Once I bind data to header gridview.
The sub to fill detail gridview called several times.
The event trigger is at
Private Sub dgvHeader_SelectionChanged (sender As Object, e As EventArgs) Handles dgvHeader.SelectionChanged
Me.Open_Data_Detail()
Screen_Function.Focusing_C ontrol(dgv Header)
End Sub
How could I prevent this ?
Thank you.
I have a header and detail gridview.
Once I bind data to header gridview.
The sub to fill detail gridview called several times.
The event trigger is at
Private Sub dgvHeader_SelectionChanged
Me.Open_Data_Detail()
Screen_Function.Focusing_C
End Sub
How could I prevent this ?
Thank you.
ASKER
Hi Ryan,
This is windows app ?
Thank you.
This is windows app ?
Thank you.
if this is Windows App, firstly, you can initial a variable with a default value.
once your stuff is executed, try to set it with another value, so that when that event is triggered again, it won't execute the same codes again, like:
once your stuff is executed, try to set it with another value, so that when that event is triggered again, it won't execute the same codes again, like:
Dim isFirstTime As Boolean = True
Private Sub dgvHeader_SelectionChanged(sender As Object, e As EventArgs) Handles dgvHeader.SelectionChanged
If isFirstTime Then
' your original stuffs to do
isFirstTime = false
Else
' if it's subsequent events
End If
End Sub
ASKER
I have done this before at form load.
sub Form_Load
blnload = true
blnload = false
End sub
After the false, the dgvHeader_SelectionChanged still trigger several times.
Thank you.
sub Form_Load
blnload = true
blnload = false
End sub
After the false, the dgvHeader_SelectionChanged
Thank you.
so you only want to do it once for codes below OR you want to do it after first time your header is changed?
Me.Open_Data_Detail()
Screen_Function.Focusing_Control(dgvHeader)
ASKER
-so you only want to do it once for codes below OR you want to do it after first time your header is changed?
Yes.
Thank you.
Yes.
Thank you.
ASKER
-so you only want to do it once for codes below OR you want to do it after first time your header is changed?
Just once.
Thank you.
Just once.
Thank you.
ASKER
Just once when refresh header.
Thank you.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ryan,
When blnload will bet set to true again in order to open detail ?
Thank you.
When blnload will bet set to true again in order to open detail ?
Thank you.
ASKER
If I moving around header grid using mouse or updown key ?
Thank you.
Thank you.
You can set master/details view using bindingsources via code or at design time - bind master grid to parent table (as datasource) and details grid to same datasource and set datamember to child table
ASKER
Hi Ark,
What is the advantage/disadvantage of using binding and not ?
Thank you.
What is the advantage/disadvantage of using binding and not ?
Thank you.
ASKER
Using binding :
What if I show I pop up form to add/update/delete data, how to refresh it ?
Thank you.
What if I show I pop up form to add/update/delete data, how to refresh it ?
Thank you.
When blnload will bet set to true again in order to open detail ?if your datagrid is in a form and you closed it, the next time when you re-open the form, the initial value is always set as true. for subsequent refreshed, it should be remained as false.
ASKER
Private Sub dgvHeader_SelectionChanged (sender As Object, e As EventArgs) Handles dgvHeader.SelectionChanged
If blnload Then
Me.Open_Data_Detail()
Screen_Function.Focusing_C ontrol(dgv Header)
blnload = false
End If
End Sub
It is always false. Means Me.Open_Data_Detail() never get called.
Thank you.
If blnload Then
Me.Open_Data_Detail()
Screen_Function.Focusing_C
blnload = false
End If
End Sub
It is always false. Means Me.Open_Data_Detail() never get called.
Thank you.
did you add this line on top of your codes?
Dim blnload As Boolean = True
ASKER
- did you add this line on top of your codes?
Sure, then when it is set to true again ?
this is not local variable.
If blnload Then
endif
Thank you.
Sure, then when it is set to true again ?
this is not local variable.
If blnload Then
endif
Thank you.
this is not local variable.do you have a sample to upload here for better illustration?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi All,
Thank you very much for your help.
Thank you very much for your help.
Open in new window