0

我的班级有 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:第一个构造函数只是创建NEW空白页面,第二个构造函数是创建NOT NEW(编辑页面),所以我传递了id并填充了所有控件(文本框,备忘录等......)

4

3 回答 3

1

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

  // ...
}
于 2012-05-02T08:28:46.037 回答
0

当你想要绑定事件处理程序时,放置断点并查看lookUpEdit_Dest,我认为这个var没有初始化,所以你需要从第二个构造函数添加初始化到第一个。

于 2012-05-02T08:33:42.917 回答
0

而是创建 Construct_Page(); 只需放入 Form_Load()

于 2012-05-02T11:56:58.443 回答