BindingSource 元件範例

更新:2007 年 11 月

這個範例會示範如何將 BindingSource 元件繫結至 Type

BindingSource 元件可以繫結至型別以及記憶體中的物件。在這個範例中,BindingSource 是繫結至 Flag 型別,但 flagName 和 flagImage 控制項則透過 BindingSource,繫結至 Flag 型別的屬性。

如需使用這些範例的詳細資訊,請參閱下列主題:

安全性注意事項:

這個程式碼範例僅供概念說明之用,同時因為範例中的程式碼撰寫並沒有周全的顧及所有安全性問題,所以本範例不適用於實際執行的應用程式或網站中。如果使用者擅自將範例程式碼用於其他意圖而導致連帶事件或重大損害時,Microsoft 將不承擔任何責任。

若要使用命令提示字元建置及執行範例

  1. 在命令提示字元中,巡覽至您用來儲存未壓縮的範例檔案的位置。

  2. 巡覽至 BindingSourceSample 目錄下其中一個語言特定子目錄。

  3. 輸入 msbuild,使用提供的方案 (.sln) 檔來建置範例。

  4. 輸入 cd BindingSourceSample\bin\Debug,以巡覽至可執行檔所在的位置。

  5. 輸入 BindingSourceSample.exe,以執行範例。

若要使用 Visual Studio 建置和執行這個範例

  1. 在 [Windows 檔案總管] 中,巡覽至您用來儲存未壓縮的範例檔案的位置。

  2. 巡覽至 BindingSourceSample 目錄下其中一個語言特定子目錄。

  3. 按兩下方案 (.sln) 檔,即可在 Visual Studio 中開啟該方案檔。

  4. 在 Visual Studio 中,按 F5 進行建置並執行範例。

若要使用 BindingSourceSample

  1. 按一下 [加入] 按鈕,建立 Flag 物件,並加入至 BindingSource

  2. 按一下 [< 和 >] 按鈕,使用 BindingSource,在 BindingSource 項目之間詳細巡覽。positionIndicatorTextBox 控制項會顯示目前 BindingSource 項目的位置,以及 BindingSource 項目計數。

示範

請參閱

工作

HOW TO:將 Windows Form 控制項繫結至型別

參考

Panel

BindingSource

BindingNavigator

DataGridView

System.Collections.IList

System.ComponentModel.IBindingList

System.ComponentModel.IEditableObject