共用方式為


BindingSource.Current 屬性

定義

取得清單中的目前項目。

public:
 property System::Object ^ Current { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public object Current { get; }
[System.ComponentModel.Browsable(false)]
public object? Current { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Current : obj
Public ReadOnly Property Current As Object

屬性值

Object,表示由 List 屬性所表示的基礎清單中的目前項目;如果該清單沒有任何項目,則為 null

屬性

範例

下列程式碼範例示範 Current 屬性。 若要執行此範例,請將程式碼貼到表單中,並從表單 Load 的事件處理方法呼叫 PopulateBindingSourceWithFonts 方法。

  public BindingSource bindingSource1 = new BindingSource();
  TextBox box1 = new TextBox();

  private void PopulateBindingSourceWithFonts()
  {
      bindingSource1.CurrentChanged += new EventHandler(bindingSource1_CurrentChanged);
      bindingSource1.Add(new Font(FontFamily.Families[2], 8.0F));
      bindingSource1.Add(new Font(FontFamily.Families[4], 9.0F));
      bindingSource1.Add(new Font(FontFamily.Families[6], 10.0F));
      bindingSource1.Add(new Font(FontFamily.Families[8], 11.0F));
      bindingSource1.Add(new Font(FontFamily.Families[10], 12.0F));
      DataGridView view1 = new DataGridView();
      view1.DataSource = bindingSource1;
      view1.AutoGenerateColumns = true;
      view1.Dock = DockStyle.Top;
      this.Controls.Add(view1);
      box1.Dock = DockStyle.Bottom;
      box1.Text = "Sample Text";
      this.Controls.Add(box1);
      box1.DataBindings.Add("Text", bindingSource1, "Name");
      view1.Columns[7].DisplayIndex = 0;
  }

  void bindingSource1_CurrentChanged(object sender, EventArgs e)
  {
      box1.Font = (Font)bindingSource1.Current;
  }
 Private WithEvents bindingSource1 As New BindingSource()
 Private box1 As New TextBox()

 
 Private Sub PopulateBindingSourceWithFonts()
   
     bindingSource1.Add(New Font(FontFamily.Families(2), 8.0F))
     bindingSource1.Add(New Font(FontFamily.Families(4), 9.0F))
     bindingSource1.Add(New Font(FontFamily.Families(6), 10.0F))
     bindingSource1.Add(New Font(FontFamily.Families(8), 11.0F))
     bindingSource1.Add(New Font(FontFamily.Families(10), 12.0F))
     Dim view1 As New DataGridView()
     view1.DataSource = bindingSource1
     view1.AutoGenerateColumns = True
     view1.Dock = DockStyle.Top
     Me.Controls.Add(view1)
     box1.Dock = DockStyle.Bottom
     box1.Text = "Sample Text"
     Me.Controls.Add(box1)
     view1.Columns("Name").DisplayIndex = 0
     box1.DataBindings.Add("Text", bindingSource1, "Name")
     
 End Sub
  
 Sub bindingSource1_CurrentChanged(ByVal sender As Object, ByVal e As EventArgs) _
     Handles bindingSource1.CurrentChanged
     box1.Font = CType(bindingSource1.Current, Font)
 End Sub

備註

Current使用 屬性來存取目前的專案,但使用 List 屬性來取得整個清單。 若要判斷目前物件的類型,請使用 GetTypeToString 方法。

若要變更目前的專案,請將 Position 屬性設定為新的整數值,或使用其中一個導覽方法,例如 MoveNext

適用於

另請參閱