2012-11-21 48 views
0

我不太熟悉bindingsources。簡單的問題是:如何將圖表綁定到數據源,以便在BindingNavigator更改時圖表顯示更新?c#圖表bindingsource更新

我的長篇大論的解釋是如下:

我有我已導入C#2010 VS Express中的數據源。這是一個相關的數據集,因爲有兩個表格(Asset,Historical_prices),其中每個資產都有一個相關的歷史價格表。

我簡單地將我的數據源拖放到窗體中,並能夠在BindingNavigator的幫助下創建我想要的視圖。我也將Historical_prices表的DataGrid視圖拖到表單中,並在BindingNavigator被點擊時更新。

然後我在表單中創建了一個圖表,我選擇了DataSource作爲historical_pricesBindingSource。它加載

我希望能夠更改具有不同Historical_prices圖表時BindingBavigator更改,但它目前doesnt。有任何想法嗎?

我試着在BindingNavigatorSaveItem_Click事件中添加chart1.Update();,但沒有骰子。

謝謝你親切

回答

0

綁定需要實際上是數據綁定而不是剛分配。你所做的基本上是在初始化或賦值過程中運行時創建的一次性綁定。

這意味着當目標(數據源)由視圖創建時,您的目標(圖表)僅更新一次。

你在找什麼是雙向綁定。以便Target更新ANYTIME Source被修改。

要達到此目的,您通常需要使用雙向綁定語法將DataSource綁定到TargetProperty。

<Toolkit:Chart x:Name="myChart" DataSource="{Binding historical_PricesDataSource, Mode=TwoWay}" /> 

儘管您的數據源需要實現INotifyPropertyChanged接口,以便通知UI它需要更新。

的代碼用於實現INotifyPropertyChanged的是:

公共事件PropertyChangedEventHandler的PropertyChanged =代表{};

// This method is called by the Set accessor of each property. 
    // The CallerMemberName attribute that is applied to the optional propertyName 
    // parameter causes the property name of the caller to be substituted as an argument. 
    private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 

對於INotifyPropertyChanged的更多信息:http://msdn.microsoft.com/en-us/library/ms229614.aspx

+0

太感謝你了......我真的很感激徹底explination – AbeeCrombie

+0

呸,我在哪裏插入代碼? – AbeeCrombie

+0

可以使用工具包代碼 –