我班上有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)
时,它会触发事件处理程序。
这是正常的吗?
它从Main表单调用的第一个构造函数
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并填充了所有控件(文本框,备忘录等等)
答案 0 :(得分: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);
// ...
}
答案 1 :(得分:0)
当你想要bind eventhandler时,把断点放在lookUpEdit_Dest上,我认为这个var没有初始化,所以你需要将第二个构造函数的初始化添加到第一个。
答案 2 :(得分:0)
改为创建Constuct_Page();只需输入Form_Load()