簡體   English   中英

C#相當於Delphi的DisableControls / EnableControls

[英]C# equivalent of Delphi's DisableControls/EnableControls

什么是Delphi的DisableControls / EnableControls方法的C#等價物(用於在迭代底層數據集時禁用數據綁定控件的更新)? 我用谷歌搜索了半個小時,沒有找到答案......

我有一個列表框和一個綁定到綁定源的豐富編輯框,但我需要執行一個迭代整個數據集的操作,並且當我在底層數據集中移動時,兩個控件都會更新。 在Delphi中,這很容易:將在DisableControlsEnableControls之間進行迭代的塊包含EnableControls 我找不到C#/ .NET等價物,我看起來真的很難!

IIRC,將Enabled設置為false不會阻止控件對WinForms中的數據更改做出反應。

ListBox這樣的集合綁定控件通常具有BeginUpdate()EndUpdate() ,這些方法暫時禁用了可視更新。

此外,DarkSquirrel提到的財產可能值得一看

我現在無權訪問Visual Studio,所以我無法對此進行測試,但請查看控件實例的方法。 代碼如:

// 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;  

該屬性的確切名稱可能略有不同,但我很確定這就是它的本質。

到目前為止,我知道,你不需要在C#中使用Disiable / EnableControls,因為這種類型的DataSet不適用於當前游標,如Delphi TDataSets。

我假設您使用的是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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM