Re: Re-number a column for all rows in RowChanged event?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

You make your life easier if you don't look for a way to prevent events to
be triggered, but more
a way to prevent event handler code to be executed.

1) In the case you don't want delegate event code to be executed, simply
toggle a class global
flag and check first in the event handler if the flag is set in order to
block the rest of the code
to execute.

For example if you change the Text property of a TextBox in your code, but
only want user changes
to be handled by your delegate TextChanged :

// Class global event blocking flags. (don't forget to initialize it -for
example in constructor-)
private bool blockTextChangedEvents;
...
// Text changed event handler.
private void myTextBox_TextChanged(object sender, System.EventArgs e)
{
// Event blocking security.
if (blockTextChangedEvents) return;
// Event handler code.
...
}
...
// Some function wich changes the Text property of myTextBox
private void ChangeText(string givenNewText)
{
// Set event blocking flag.
blockTextChangedEvents = true;
// Change Text.
myTextBox.Text = givenNewText;
// Reset event blocking flag.
blockTextChangedEvents = false;
}

2) The more tricky is if you want to avoid base event handler code to
execute ; you can simply derive
the class, a DataGrid in your case and override the native handler, where
you upon the event blocking
flag's state, call or do not call the base handler.

But this can be dangerous. I do not know the specifics of the internal
householding of your RowChanged event
(it could be just firing delegate events, but also serious householding -so
you need to test and to find out-).

- If there is householding it may be enough to just call your base handler
once after a series of changes, so in the
same row renumbering function you toggle the block flag to prevent execution
(of your overridden event handler) and after all the changes you call the
base event handler (so once).

- But if there is an incremental maintenance of state (so where it is
necessary to have the handler executed at each
single change) then let it be.

Hope this helps,

AinO.

"Tim Nelson" <timnelsATgmail.com> wrote in message
news:#s8gs4gZFHA.4036@xxxxxxxxxxxxxxxxxxxxxxx
> I have the need to have a column called "order" in a dataview that is
> tied to a grid. When the use changes the "order" field in the grid and
> moves to another row I want to trap the RowChanged/ing event and
> renumber all the rows. Problem I think I am having is as I renumber the
> rows, the row changed event will fire over and over again.
> Any ideas?
> Thanks.


.



Relevant Pages

  • Re: Instantiating objects and event handlers for delegates
    ... take a look at the following delegate event handler code: ... The event handler quickly stuffs them into a collection. ... "Dale Preston" wrote: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: role based security to enable controls
    ... One approach is to perform a role-based security check in the ... "VisibleChanged" event (or override "OnVisibleChanged" if appropriate). ... and then use reflection in the event handler code to get the ...
    (microsoft.public.dotnet.security)
  • Re: Problem with global variables and buttons
    ... (here: onClick) ... makes its value execute automatically when the corresponding ... The event handler code is ... value by executing an event handler, ...
    (comp.lang.javascript)
  • Re: User Control events
    ... where is the event handler code? ... > event is always null so never fires the Click event. ... >> Ollie Riches ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: .NET Events
    ... programmatic control is transferred to the event ... When the event handler code has been completed, ... > letting OnFireEvent continue running after firing the event? ...
    (microsoft.public.dotnet.framework)