BindingGroup.GetValue(Object, String) Method

Definition

지정된 속성 및 항목에 대해 제안된 값을 반환합니다.Returns the proposed value for the specified property and item.

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

Parameters

item
Object

지정된 된 속성을 포함 하는 개체입니다.The object that contains the specified property.

propertyName
String

제안된 값을 가져올 속성입니다.The property whose proposed value to get.

Returns

Object

제안 된 속성 값입니다.The proposed property value.

Exceptions

지정된 항목 및 속성에 대한 바인딩이 없는 경우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.

Examples

다음 예제는 여러 고객을 입력 하 고 각 고객에 게는 영업 담당자를 할당 하 라는 메시지는 애플리케이션의 일부입니다.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;
        }
        else
        {

            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
        Else

            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

Remarks

이 메서드를 사용 합니다 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 정수 형식의 속성에 바인딩된 데이터 및 ValidationRule 를 호출 하는 GetValue(Object, String) 에 해당 ValidationStepRawProposedValue, 메서드는 문자열을 반환 합니다.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 에 해당 ValidationStepConvertedProposedValue, 메서드가 바인딩의 변환기에서 반환 되는 형식에 관계 없이 반환 합니다.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.

Applies to