BindingGroup.GetValue(Object, String) メソッド


指定されているプロパティと項目に対して提示されている値を返します。Returns the proposed value for the specified property and item.

 System::Object ^ GetValue(System::Object ^ item, System::String ^ propertyName);
public object GetValue (object item, string propertyName);
member this.GetValue : obj * string -> obj
override this.GetValue : obj * string -> obj
Public Function GetValue (item As Object, propertyName As String) As Object



指定されているプロパティを含むオブジェクト。The object that contains the specified property.


提示されている値を取得するプロパティ。The property whose proposed value to get.



提示されているプロパティ値。The proposed property value.


指定されている項目とプロパティにはバインディングがありません。There is not a binding for the specified item and property.

変換エラーまたは前の検証ルールが失敗したために、指定されているプロパティの値は使用できません。The value of the specified property is not available, due to a conversion error or because an earlier validation rule failed.

次の例は、複数の顧客を入力し、各顧客に販売担当者を割り当てるようにユーザーに求めるアプリケーションの一部です。The following example is part of an application that prompts the user to enter multiple customers and assign a sales representative to each customer. アプリケーションは、営業担当者と顧客が同じリージョンに属していることを確認します。The application checks that the sales representative and the customer belong to the same region. この例は、メソッドを使用して、 Validate GetValue(Object, String) 顧客が入力した値を取得するメソッドを示しています。The example shows the Validate method, which uses the GetValue(Object, String) method to get values that the customer entered.

public class AreasMatch : ValidationRule
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        BindingGroup bg = value as BindingGroup;
        Customer cust = bg.Items[0] as Customer;
        if (cust == null)
            return new ValidationResult(false, "Customer is not the source object");

        Region region = (Region)bg.GetValue(cust, "Location");
        ServiceRep rep = bg.GetValue(cust, "ServiceRepresentative") as ServiceRep;
        string customerName = bg.GetValue(cust, "Name") as string;

        if (region == rep.Area)
            return ValidationResult.ValidResult;

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0} must be assigned a sales representative that serves the {1} region. \n ", customerName, region);
            return new ValidationResult(false, sb.ToString());
Public Class AreasMatch
    Inherits ValidationRule
    Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As ValidationResult
        Dim bg As BindingGroup = TryCast(value, BindingGroup)
        Dim cust As Customer = TryCast(bg.Items(0), Customer)

        If cust Is Nothing Then
            Return New ValidationResult(False, "Customer is not the source object")
        End If

        Dim region As Region = CType(bg.GetValue(cust, "Location"), Region)
        Dim rep As ServiceRep = TryCast(bg.GetValue(cust, "ServiceRepresentative"), ServiceRep)
        Dim customerName As String = TryCast(bg.GetValue(cust, "Name"), String)

        If region = rep.Area Then
            Return ValidationResult.ValidResult

            Dim sb As New StringBuilder()
            sb.AppendFormat("{0} must be assigned a sales representative that serves the {1} region. " & vbLf & " ", customerName, region)
            Return New ValidationResult(False, sb.ToString())
        End If
    End Function
End Class


メソッドでこのメソッドを使用して、 ValidationRule.Validate ソースにコミットする値を取得します。Use this method in the ValidationRule.Validate method to get the value to be committed to the source. 戻り値の型は、が発生する段階によって異なり ValidationRule ます。The type of the return value depends on the stage at which the ValidationRule occurs. たとえば、 TextBox が integer 型のプロパティにバインドされたデータであり、を呼び出したがに設定されている場合、 ValidationRule GetValue(Object, String) ValidationStep RawProposedValue メソッドは文字列を返します。For example, if a TextBox is data bound to a property of type integer and the ValidationRule that calls GetValue(Object, String) has its ValidationStep set to RawProposedValue, the method returns a string. がに設定されている場合 ValidationRule ValidationStep ConvertedProposedValue 、メソッドは、バインディングのコンバーターによって返される任意の型を返します。If the ValidationRule has its ValidationStep set to ConvertedProposedValue, the method returns whatever type that is returned by the binding's converter. この例では、 GetValue(Object, String) は通常、整数を返します。In this example, GetValue(Object, String) usually returns an integer.