2017-07-24 65 views
0

有一個Windows窗體應用程序與幾個字段,應該由databindng更新。 所有字段都將包含在'this'部分中,所有字段都將顯示在附加的標籤中,但不包含[BaustelleName]。c#WindowsForms數據綁定不會更新所有字段

PropertyChanged?.Invoke(this, e); ScreenShoot one

一起工作的來源是:

public string BaustelleName 
    { 
     get { return string.IsNullOrEmpty(this.sName) ? null : sName; } 
     set 
     { 
      sName = value; 
      InvokePropertyChanged(new PropertyChangedEventArgs("BaustelleName")); 
     } 
    } 

    public string BaustelleZusatz 
    { 
     get { return string.IsNullOrEmpty(this.sZusatz) ? null : sZusatz; } 
     set 
     { 
      sZusatz = value; 
      InvokePropertyChanged(new PropertyChangedEventArgs("BaustelleZusatz")); 
     } 
    } 

...

protected void BindControls() 
    { 
     try 
     { 
      Binding bnd = null; 
      cBindung bnd_Helper = new cBindung(); 

      // txt_Baustelle ---------------------------------------------------------------------------- 
      parent.txt_Baustelle.DataBindings.Clear(); 
      bnd = new Binding("Text", this, "BaustelleNr", true, DataSourceUpdateMode.OnPropertyChanged); 
      parent.txt_Baustelle.DataBindings.Add(bnd); 

      //lbl_AdrBaustelle_Zl1.Text = adr.VornameName; ---------------------------------------------- 
      parent.lbl_AdrBaustelle_Zl1.DataBindings.Clear(); 
      bnd = new Binding("Text", this, "BaustelleName"); 
      parent.lbl_AdrKunde_Zl1.DataBindings.Add(bnd); 

      //lbl_AdrBaustelle_Zl2.Text = adr.Zusatz; --------------------------------------------------- 
      parent.lbl_AdrBaustelle_Zl2.DataBindings.Clear(); 
      bnd = new Binding("Text", this, "BaustelleZusatz"); 
      parent.lbl_AdrBaustelle_Zl2.DataBindings.Add(bnd);  //Zusatz 

...

public void InvokePropertyChanged(PropertyChangedEventArgs e) 
    { 
     PropertyChanged?.Invoke(this, e); 
    } 

...也適用於其他領域。 我發現[BaustelleName] nevver的getter被調用,而每次調用[InvokePropertyChanged]時調用所有其他的。

什麼可能是錯的?

回答

0

要添加的結合到了錯誤的標籤:你將它添加到lbl_ArdKunde而不是lbl_AdrBaustelle

//lbl_AdrBaustelle_Zl1.Text = adr.VornameName; --------------------------------------- 
    parent.lbl_AdrBaustelle_Zl1.DataBindings.Clear(); 
    bnd = new Binding("Text", this, "BaustelleName"); 
    parent.lbl_AdrKunde_Zl1.DataBindings.Add(bnd); 
+0

@ nicoYour'e權利;非常感謝你,併爲這個愚蠢的問題表示歉意。正如我們用德語所說:「有時你看不到眼前的手」 – pfotenh