2017-06-21 16 views
0

所以我無法獲得正確的數據顯示在我的子窗體中。需要幫助顯示使用數據綁定的布爾屬性狀態

我正在使用子窗體來列出有關在條目(父)窗體中選擇的當前對象的詳細信息。

我的問題在於我的綁定對象。我有一個布爾屬性(IsAutomatic),並在我想要的細節表單中顯示爲「自動」,當爲「手動」時顯示。

我似乎無法得到一個字符串來顯示我的表單,只有「真」或「假」這個字其實是價值,而不是我想要的。

下面是我用過的代碼。

Binding _transmission = new Binding("Text", _formDataSource.Current, "IsAutomatic"); 
     //how the hell do i do this? 
_transmission.FormatString = string.Format(//and i've tried a ternary operator here to display literals depending on if _transission is true or false, but this is a binding object and not a bool data type. I attempted to try a cast on the _transmission object, but the IDE did not like it at all. 
     lblTransmission.DataBindings.Add(_transmission); 
    // do i want code the ternary here 
(lblTransmission.Text.Equals("true")) ? "Automatic" : "Manual"; //this brought up errors too... 

任何幫助將不勝感激,因爲我已經在這一段時間了。

回答

0

我可以用一個簡單的鑄件做到這一點...

Vehicle _vehicle; 

再後來就

_vehicle = (Vehicle)_bindingSource.Current; 

並獲得所需的輸出爲我的標籤

lblTransmission.DataBindings.Add("Text", _vehicle, "IsAutomatic",true); 
lblTransmission.Text = String.Format("{0}", 
(_vehicle.IsAutomatic) ? "Automatic" : "Manual") 

我希望這可以幫助沿途的人。如果有人有任何建議或批評,請隨時告訴我你的想法...我仍然只是一名學生(只剩下2個學期!!)。 謝謝。