Export (0) Print
Expand All

Binding.PropertyName Property

Gets or sets the name of the control's data-bound property.

[Visual Basic]
Public ReadOnly Property PropertyName As String
[C#]
public string PropertyName {get;}
[C++]
public: __property String* get_PropertyName();
[JScript]
public function get PropertyName() : String;

Property Value

The name of a control property to bind to.

Remarks

Use the PropertyName to specify the control property that you want to bind to a list in a data source. Most commonly, you bind a display property such as the Text property of a TextBox control. However, because you can bind any property of a control, you can programmatically create controls at run time using data from a database.

Example

The following example prints the PropertyName value of each Binding for each control on a form.

[Visual Basic] 
Private Sub PrintPropertyNameAndIsBinding
    Dim thisControl As Control
    Dim thisBinding As Binding
    For Each thisControl In Me.Controls
        For Each thisBinding In thisControl.DataBindings
            Console.WriteLine(ControlChars.CrLf & thisControl.ToString)
            ' Print the PropertyName value for each binding.
            Console.WriteLine(thisBinding.PropertyName)
        Next
    Next
End Sub
End Class

[C#] 
private void PrintPropertyNameAndIsBinding()
{
   foreach(Control thisControl in this.Controls)
   {
      foreach(Binding thisBinding in thisControl.DataBindings)
      {
         Console.WriteLine("\n" + thisControl.ToString());
         // Print the PropertyName value for each binding.
         Console.WriteLine(thisBinding.PropertyName);
      }
   }
}


[C++] 
private:
   void PrintPropertyNameAndIsBinding() {
      System::Collections::IEnumerator* myEnum = this->Controls->GetEnumerator();
      while (myEnum->MoveNext()) {
         Control* thisControl = __try_cast<Control*>(myEnum->Current);
         System::Collections::IEnumerator* myEnum = thisControl->DataBindings->GetEnumerator();
         while (myEnum->MoveNext()) {
            Binding* thisBinding = __try_cast<Binding*>(myEnum->Current);
            Console::WriteLine(S"\n {0}", thisControl);
            // Print the PropertyName value for each binding.
            Console::WriteLine(thisBinding->PropertyName);
         }
      }
   }

[JScript] 
private function PrintPropertyNameAndIsBinding()
{
   for(var thisControl : Control in this.Controls)
   {
      for(var thisBinding : Binding in thisControl.DataBindings)
      {
         Console.WriteLine("\n" + thisControl.ToString());
         // Print the PropertyName value for each binding.
         Console.WriteLine(thisBinding.PropertyName);
      }
   }
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Binding Class | Binding Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft