Hello everybody,
I have a little "problem".
I have a DataGridView that is loaded automatically by code sometimes, and
manually by the user other times.
When the user introduces data in the DataGridView, there are some events
that control the introduced data for any errors the user can do. That's OK.
But when the data is loaded automatically, it is supposed that this data is
correct, so I don't need that these events are called.
I want to do that because with a lot of data, the load is very slowly, and
with the events disabled it takes only few seconds.
Anyone can help me, and tell me how can I disable these events?
I have done that, but it doesn't work.
Thanks in advance!
Marc
private void EventDisabler(b ool Enable)
{
if (Enable)
{
//Enable event handler
dgvItems.CellCl ick += new DataGridViewCel lEventHandler(d gvItems_CellCli ck);
dgvItems.CellVa lueChanged += new
DataGridViewCel lEventHandler(d gvItems_CellVal ueChanged);
dgvItems.CellEn dEdit += new
DataGridViewCel lEventHandler(d gvItems_CellEnd Edit);
dgvItems.CellVa lidated += new
DataGridViewCel lEventHandler(d gvItems_CellVal idated);
dgvItems.RowEnt er += new DataGridViewCel lEventHandler(d gvItems_RowEnte r);
dgvItems.RowLea ve += new DataGridViewCel lEventHandler(d gvItems_RowLeav e);
dgvItems.RowVal idated += new
DataGridViewCel lEventHandler(d gvItems_RowVali dated);
}
else
{
//Disable event handler
dgvItems.CellCl ick -= new DataGridViewCel lEventHandler(d gvItems_CellCli ck);
dgvItems.CellVa lueChanged -= new
DataGridViewCel lEventHandler(d gvItems_CellVal ueChanged);
dgvItems.CellEn dEdit -= new
DataGridViewCel lEventHandler(d gvItems_CellEnd Edit);
dgvItems.CellVa lidated -= new
DataGridViewCel lEventHandler(d gvItems_CellVal idated);
dgvItems.RowEnt er -= new DataGridViewCel lEventHandler(d gvItems_RowEnte r);
dgvItems.RowLea ve -= new DataGridViewCel lEventHandler(d gvItems_RowLeav e);
dgvItems.RowVal idated -= new
DataGridViewCel lEventHandler(d gvItems_RowVali dated);
}
} 4 16861
I take it by "it doesn't work" you mean that they are still firing.
What you have should work, if used correctly. Is it possible that it has
been enabled twice (without an unsubscribe) through some route? As if so, it
will be subscribed twice, and fired twice. This will a: be slower, and b: if
you unsubscribe (-=) it will only remove the first found instance, perhaps
leaving one behind.
If this is the case, I would sugggest either keeping a bool field to track
if you think you are currently subscribed, or, *always* run the -= (which
unsubscribes if possible), then (if enabled) run the +=, so you can only
ever have 1 instance of each. The bool is cleaner.
Marc
Thanks Marc,
I thought before to do that with the bool field, but it will always rise the
event and then compare the bool, isn't it?
Finally I choose the option to run always the -= .
Thanks a lot for your help.
Marc
"Marc Gravell" <ma**********@g mail.comescribi ó en el mensaje
news:e0******** ******@TK2MSFTN GP04.phx.gbl...
>I take it by "it doesn't work" you mean that they are still firing.
What you have should work, if used correctly. Is it possible that it has
been enabled twice (without an unsubscribe) through some route? As if so,
it will be subscribed twice, and fired twice. This will a: be slower, and
b: if you unsubscribe (-=) it will only remove the first found instance,
perhaps leaving one behind.
If this is the case, I would sugggest either keeping a bool field to track
if you think you are currently subscribed, or, *always* run the -= (which
unsubscribes if possible), then (if enabled) run the +=, so you can only
ever have 1 instance of each. The bool is cleaner.
Marc
No, I meant in your method... i.e.
bool eventsBound = false;
void BindEvents(bool enable) {
if(enable && eventsBound) return; // nothing to do; already bound...
if(!enable && !eventsBound) return; // nothing to do; not bound...
if(enable) {
someControl.Som eEvent += someHandler;
someControl.Som eOtherEvent += someOtherHandle r;
} else {
someControl.Som eEvent -= someHandler;
someControl.Som eOtherEvent -= someOtherHandle r;
}
eventsBound = enable;
}
Marc
Thank you very much for your help.
It works fine now.
Marc
"Marc Gravell" <ma**********@g mail.comescribi ó en el mensaje
news:em******** ******@TK2MSFTN GP03.phx.gbl...
No, I meant in your method... i.e.
bool eventsBound = false;
void BindEvents(bool enable) {
if(enable && eventsBound) return; // nothing to do; already bound...
if(!enable && !eventsBound) return; // nothing to do; not bound...
if(enable) {
someControl.Som eEvent += someHandler;
someControl.Som eOtherEvent += someOtherHandle r;
} else {
someControl.Som eEvent -= someHandler;
someControl.Som eOtherEvent -= someOtherHandle r;
}
eventsBound = enable;
}
Marc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tuong Do |
last post by:
Hi,
I am going to insert a large amount (200,000 records) of data into a table
Is there a way that I can temporarily disable the log? so that the insertion
run faster
Thanks in advance
|
by: Dw70 |
last post by:
I need write simple program with work in background
and have only one function when it is run F1 I disable
and when I pres for example ctrl+k it (program is terminate)
maybe somebody have similar program or part of code I don't know
how get signal F1 pressing and neutralize it?
|
by: ORC |
last post by:
Hi,
Is it possible to disable an event like e.g. disabling:
private void textBox1_TextChanged(object....) ?
Thanks,
Ole
|
by: Scott Emick |
last post by:
How can I disable events for the controls on a form? I tried setting the
form's enable property to false, but that doesn't stop events from firing on
its controls.
I need to temporarily disable a form and load values into controls without
any events firing, then re-enable the form.
--
Scott Emick
Web Programmer
|
by: nick |
last post by:
Is it possible to disable/suppress alert popups in javascript? I need
to write a function that will loop through a form's inputs and
"manually" fire their onchange events (if found). Some of those
functions could popup alert boxes which I'd like to be able to
temporarily suppress.
Thanks for any help.
| |
by: Jon Slaughter |
last post by:
Is there any method to temporarily disable focus changing?(I assume only
method is tab or mouse?) This problem has been tieing me up for a while and
nothing seems to work. The only thing that I *know* will work is to disable
all tab stops on all controls. This brute force method doesn't seem like a
good idea though.
What I wanted to do was take control the control enter/leave and mouse
enter/leave and "switch back" the focus when it is...
|
by: Gary Jefferson |
last post by:
Suppose I have 3 modules that belong to a project, 'A', 'A.a' and 'B',
and each module has its own logger, created with:
module1logger = logging.getLogger('project.A')
and
module2logger = logging.getLogger('project.A.a')
and
|
by: Vince C. |
last post by:
Hi all.
I've installed Bloodshed Dev-C++ on a Windows 2000 SP4 machine. I'm using
MinGW 3.4.2.
I'd like to temporarily disable standard functions to write to stderr, i.e.
for instance redirect stderr to a temporary file (or /dev/null but is there
an equivalent under Windows? Is it "nul:") and then to *restore* the
default stderr so that standard library functions that write to stderr
produce output again.
|
by: hsriat |
last post by:
How can I temporarily disable vertical scrollbar?
I have replaced confirmation boxes and alert boxes with inlay popup DIVs. But while they are on the screen, I need to disable scrollbar of the page so that user may not access the main page (just like in conformation boxes).
Also I need to disable the main page leaving that popup DIV.
Scrollbar is the main issue.
How can I do it?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |