What is the C# equivalent of Delphi's DisableControls
/EnableControls
methods (used to disable updating of databound controls while iterating through the underlying dataset)? I have googled for half an hour and did not find an answer...
I have a list box and a rich edit box bound to a binding source, but I need to do an operation that iterates through the entire dataset, and both controls get updated as I move through the underlying dataset. In Delphi this is easy enough: enclose the block that does the iteration between DisableControls
and EnableControls
. I can't find the C#/.NET equivalent, and I have looked really hard!
IIRC, setting Enabled
to false
does not prevent the controls from reacting to data changes in WinForms.
Collection-bound controls like the ListBox
typically have methods BeginUpdate()
and EndUpdate()
which temporarily disable visual updates.
Also, the property mentioned by DarkSquirrel might be worth a look
I don't have access to Visual Studio right now, so I can't test this, but look through the methods for the control instance. Code such as:
// set the Enabled property of
// the controls to False; this should
// disable the controls for user access
listBox.Enabled = False;
richEditBox.Enabled = False;
// perform iteration
// and other operations
// set the Enabled property back
// to True
listBox.Enabled = True;
richEditBox.Enabled = True;
The exact name of the property may differ slightly, but I'm pretty sure that this is what it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With