Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# equivalent of Delphi's DisableControls/EnableControls

Tags:

c#

dataset

delphi

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!

like image 236
Eduardo Avatar asked Apr 23 '11 22:04

Eduardo


2 Answers

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

like image 151
Sven Künzler Avatar answered Nov 11 '22 01:11

Sven Künzler


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.

like image 42
Nate Koppenhaver Avatar answered Nov 11 '22 01:11

Nate Koppenhaver