C # equivalent to Delphi DisableControls / EnableControls

What is the C # equivalent for Delphi DisableControls/ methods EnableControls(used to disable updating database controls when iterates through a basic dataset)? I tried for half an hour and did not find the answer ...

I have a list box and a rich edit box that is bound to a binding source, but I need to perform an operation that iterates over the entire dataset, and both controls are updated when I navigate through the base dataset. In Delphi, this is quite simple: enclose a block that iterates between DisableControlsand EnableControls. I cannot find the C # / equivalent. NET and I looked really hard!

+5
source share
4 answers

IIRC, setting Enabledto falsedoes not prevent controls from responding to data changes in WinForms.

Collection-bound controls, such as ListBox, typically have methods BeginUpdate()and EndUpdate()that temporarily disable visual updates.

Also, the property mentioned by DarkSquirrel may be worth a look.

+2
source

I do not have access to Visual Studio right now, so I canโ€™t verify this, but Iโ€™ll look at the methods for the control instance. Code, for example:

// 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 be slightly different, but I'm sure this is what it is.

+1
source

, WinForms, SuspendLayout/ResumeLayout.

MSDN:

private void AddButtons()
{
   // Suspend the form layout and add two buttons.
   this.SuspendLayout();
   Button buttonOK = new Button();
   buttonOK.Location = new Point(10, 10);
   buttonOK.Size = new Size(75, 25);
   buttonOK.Text = "OK";

   Button buttonCancel = new Button();
   buttonCancel.Location = new Point(90, 10);
   buttonCancel.Size = new Size(75, 25);
   buttonCancel.Text = "Cancel";

   this.Controls.AddRange(new Control[]{buttonOK, buttonCancel});
   this.ResumeLayout();
}
0

, /EnableControls #, DataSet , Delphi TDataSets.

0
source

All Articles