3
我們使用派生的Form-Classes,其中一個基本窗體類用於我們的軟件。如何以編程方式爲所有控件設置ErrorProvider圖標
在派生形式上,我們廣泛使用DataBinding來處理我們的BusinessObjects,它們都實現了IDataErrorInfo,並將錯誤消息拋出到ErrorProviders的GUI上。
我現在搜索一種方法來實現基本窗體類中的函數來獲取窗體上的所有ErrorProvider-Components,並將窗體上每個控件的IconAlignment都設置爲左(因爲右是間距問題)。
任何提示歡迎...
代碼設置IconAlignment:
private void SetErrorProviderIconAlignment(ErrorProvider errorProvider, Control control)
{
errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
foreach (Control subControl in control.Controls)
{
SetErrorProviderIcon(errorProvider, subControl);
}
}
好了,這樣的作品,但不幸的是不使用數據綁定... – 2010-05-28 06:37:59
@BeowulfOF - 我不確定你的意思?常規的ErrorProvider通過在綁定對象上實現IDataErrorInfo來支持數據綁定屬性的驗證。您需要將ErrorProvider的DataSource屬性設置爲控件綁定中使用的相同BindingSource。 – Reddog 2010-05-28 19:58:16
做到了這一點,但填充和對齊不是從子類錯誤提供程序中使用的。 – 2010-05-29 08:43:48