BindingGroup.GetValue(Object, String) 메서드

정의

지정된 속성 및 항목에 대해 제안된 값을 반환합니다.

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

매개 변수

item
Object

지정된 속성을 포함하는 개체입니다.

propertyName
String

제안된 값을 가져올 속성입니다.

반환

Object

제안된 속성 값입니다.

예외

지정된 항목 및 속성에 대한 바인딩이 없는 경우

변환 오류나 이전의 유효성 검사 규칙 실패로 인해 지정된 속성 값을 사용할 수 없는 경우

예제

다음 예제는 여러 고객을 입력 하 고 각 고객에 게는 영업 담당자를 할당 하 라는 메시지는 애플리케이션의 일부입니다. 애플리케이션 판매 담당자와 고객 동일한 지역에 속해 있는지 확인 합니다. 예제에 나와 있는 합니다 Validate 메서드를 사용 하는 GetValue(Object, String) 고객이 입력 한 값을 가져오는 방법입니다.

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

설명

이 메서드를 사용 합니다 ValidationRule.Validate 메서드는 소스에 커밋할 수 값을 가져옵니다. 반환 값 유형의 하는 단계에 따라 달라 집니다는 ValidationRule 발생 합니다. 예를 들어 경우는 TextBox 정수 형식의 속성에 바인딩된 데이터 및 ValidationRule 를 호출 하는 GetValue(Object, String) 에 해당 ValidationStepRawProposedValue, 메서드는 문자열을 반환 합니다. 경우는 ValidationRule 에 해당 ValidationStepConvertedProposedValue, 메서드가 바인딩의 변환기에서 반환 되는 형식에 관계 없이 반환 합니다. 이 예제에서는 GetValue(Object, String) 일반적으로 정수를 반환 합니다.

적용 대상