次の方法で共有


DataBinding.Expression プロパティ

評価されるデータ連結式を取得します。

Public Property Expression As String
[C#]
public string Expression {get; set;}
[C++]
public: __property String* get_Expression();public: __property void set_Expression(String*);
[JScript]
public function get Expression() : String;public function set Expression(String);

プロパティ値

評価されるデータ連結式。

使用例

[Visual Basic, C#, C++] DataBinding オブジェクトを作成し、 propertyName パラメータの値が TextDataBindingCollection の既存のオブジェクトをこれに設定する例を次に示します。 propertyName の値が TextDataBinding オブジェクトがコレクションに含まれている場合、このコードは、オブジェクトの Expression プロパティの値を返します。そのようなオブジェクトがない場合は、空の文字列が返されます。

 
' Create a Text property with accessors that obtain 
' the property value from and set the property value
' to the Text key in the DataBindingCollection class.

Public Property [Text]() As String
   Get
      Dim myBinding As DataBinding = DataBindings("Text")
      If Not (myBinding Is Nothing) Then
         Return myBinding.Expression
      End If
      Return String.Empty
   End Get
   Set
      
      If value Is Nothing OrElse value.Length = 0 Then
         DataBindings.Remove("Text")
      Else
         
         Dim binding As DataBinding = DataBindings("Text")
         
         If binding Is Nothing Then
            binding = New DataBinding("Text", GetType(String), value)
         Else
            binding.Expression = value
         End If
         ' Call the DataBinding constructor, then add
         ' the initialized DataBinding object to the 
         ' DataBindingCollection for this custom designer.
         Dim binding1 As DataBinding = CType(DataBindings.SyncRoot, DataBinding)
         DataBindings.Add(binding)
         DataBindings.Add(binding1)
      End If
      OnBindingsCollectionChanged("Text")
   End Set
End Property


[C#] 
// Create a Text property with accessors that obtain 
// the property value from and set the property value
// to the Text key in the DataBindingCollection class.
public string Text
 {
    get
    {
       DataBinding myBinding = DataBindings["Text"];
       if (myBinding != null)
       {
          return myBinding.Expression;
       }
       return String.Empty;
    }
    set
    {

       if ((value == null) || (value.Length == 0))
       {
          DataBindings.Remove("Text");
       }
       else
       {

          DataBinding binding = DataBindings["Text"];

          if (binding == null)
          {
             binding = new DataBinding("Text", typeof(string),value );
          }
          else
          {
             binding.Expression = value;
          }
          // Call the DataBinding constructor, then add
          // the initialized DataBinding object to the 
          // DataBindingCollection for this custom designer.
          DataBinding binding1=(DataBinding)DataBindings.SyncRoot;
          DataBindings.Add(binding);
          DataBindings.Add(binding1);
       }
       OnBindingsCollectionChanged("Text");
    }
 }

[C++] 
// Create a Text property with accessors that obtain
// the property value from and set the property value
// to the Text key in the DataBindingCollection class.
 public:
__property String* get_Text() {
   DataBinding* myBinding = DataBindings->Item[S"Text"];
   if (myBinding != 0) {
      return myBinding->Expression;
   }
   return String::Empty;
}
__property void set_Text(String* value) {

   if ((value == 0) || (value->Length == 0)) {
      DataBindings->Remove(S"Text");
   } else {

      DataBinding* binding = DataBindings->Item[S"Text"];

      if (binding == 0) {
         binding = new DataBinding(S"Text", __typeof(String), value);
      } else {
         binding->Expression = value;
      }
      // Call the DataBinding constructor, then add
      // the initialized DataBinding object to the
      // DataBindingCollection for this custom designer.
      DataBinding* binding1=dynamic_cast<DataBinding*>(DataBindings->SyncRoot);
      DataBindings->Add(binding);
      DataBindings->Add(binding1);
   }
   OnBindingsCollectionChanged(S"Text");
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataBinding クラス | DataBinding メンバ | System.Web.UI 名前空間 | データ連結式構文