我的类中有 2 个构造函数:
public partial class Fiche_Ordre : Le_MainForm
{
public Fiche_Ordre()
{
InitializeComponent();
Constuct_Page();
}
public Fiche_Ordre(string OrderID): this()
{
Pers_Ordre oPersOrdr = oOrder_BL.Get_OrdreOne_BL(ClientID, Convert.ToInt32(OrderID), false);
textEdit_RefExpred.Text = oPersOrdr.RefExpd;
lookUpEdit_Agence.EditValue = oPersOrdr.Agence;
lookUpEdit_Transport.EditValue = oPersOrdr.Transporteur;
lookUpEdit_Dest.EditValue = oPersOrdr.DestId;
..................
}
public void Constuct_Page()
{
try
{
ClientID = Program.Le_ClientID;
....
#region LookUpEdidt Destinataire
lookUpEdit_Dest.Properties.DataSource = Auxiliaire_BL.FillCombo_BL(false, ClientID).Tables["ComboFill"];
lookUpEdit_Dest.Properties.ValueMember = "CODE_DEST";
lookUpEdit_Dest.Properties.DisplayMember = "CODE_DEST";
LookUpColumnInfoCollection coll_Dest = lookUpEdit_Dest.Properties.Columns;
// A column to display the ProductID field's values.
coll_Dest.Add(new LookUpColumnInfo("CODE_DEST", 0, "Code Destinataire"));
// A column to display the ProductName field's values.
coll_Dest.Add(new LookUpColumnInfo("RS_NOM", 0, "Raison Social"));
// Set column widths according to their contents and resize the popup, if required.
lookUpEdit_Dest.Properties.BestFitMode = BestFitMode.BestFitResizePopup;
// Enable auto completion search mode.
lookUpEdit_Dest.Properties.SearchMode = SearchMode.AutoComplete;
// Specify the column against which to perform the search.
lookUpEdit_Dest.Properties.AutoSearchColumnIndex = 1;
lookUpEdit_Dest.EditValueChanged += new EventHandler(lookUpEdit_Dest_EditValueChanged);
#endregion
...
}
这很奇怪,因为当我使用public Fiche_Ordre()
时,它不会触发new EventHandler(lookUpEdit_Dest_EditValueChanged);
;但是当我使用public Fiche_Ordre(string OrderID)
时,它确实会触发事件处理程序。
这正常吗?
它从主窗体调用的第一个构造器
public partial class Le_MainForm : DevExpress.XtraEditors.XtraForm
{
public Le_MainForm()
{
InitializeComponent();
this.Name = "MainUSER";
if (Program.IsFA) barButtonItem_OrdList.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
}
private void barButtonItem_CreatOrdreAller_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Close_AllForm();
Program.AllerRetour = "Ordre Aller";
Fiche_Ordre f_Fiche = new Fiche_Ordre();
f_Fiche.Show();
}
第二个构造函数我称之为
public partial class Liste_Ordres : Le_MainForm
{
private void Liste_DobleClic(object sender, EventArgs e)
{
try
{
Program.OrderId = gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString();
this.Hide();
Fiche_Ordre f_Fiche = new Fiche_Ordre(gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString());
f_Fiche.Show();
}
catch (Exception excThrown)
{
MessageBox.Show(excThrown.Message);
}
}
提前谢谢你。
PS:第一个构造函数只是创建新的空白页,第二个构造函数是创建 NOT NEW(编辑页面),所以我传递了 id 并填充了所有控件(文本框、备忘录等......
EditValueChanged
句柄连接在Constuct_Page
的最后一行。因此,它仅在Constuct_Page
之后触发更改。代码的..................
部分是否更改?这听起来确实像是一个过于简化的猜测,但无论如何都值得仔细检查......
此外,我可以建议你另一个改进:
public Fiche_Ordre(string OrderID) : this.Fiche_Ordre()
{
// invokes the other constructor first, so they're guaranteed
// do be equivalent in the first part
Pers_Ordre oPersOrdr = oOrder_BL.Get_OrdreOne_BL(ClientID,
Convert.ToInt32(OrderID), false);
// ...
}
当你想要绑定事件处理程序时,放置断点并查看lookUpEdit_Dest,我认为这个 var 不初始化,所以你需要将初始化从第二个构造函数添加到第一个。
改为创建Constuct_Page(); 只需输入 Form_Load()