BindingGroup.GetValue(Object, String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 속성 및 항목에 대해 제안된 값을 반환합니다.
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
제안된 값을 가져올 속성입니다.
반품
제안된 속성 값입니다.
예외
지정된 항목 및 속성에 대한 바인딩이 없습니다.
변환 오류 또는 이전 유효성 검사 규칙이 실패했기 때문에 지정된 속성의 값을 사용할 수 없습니다.
예제
다음 예제는 사용자에게 여러 고객을 입력하고 각 고객에게 영업 담당자를 할당하라는 메시지를 표시하는 애플리케이션의 일부입니다. 애플리케이션은 영업 담당자와 고객이 동일한 지역에 속하는지 확인합니다. 이 예제에서는 메서드를 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 따라 달라집니다. 예를 들어 a TextBox 가 정수 형식의 속성에 바인딩된 데이터이고 ValidationRule 호출에 해당 GetValue(Object, String) 집합ValidationStep이 RawProposedValue 있는 경우 메서드는 문자열을 반환합니다. 해당 집합이 ValidationRule 있는 ValidationStep경우 메서드는 ConvertedProposedValue 바인딩의 변환기에서 반환되는 모든 형식을 반환합니다. 이 예제에서는 GetValue(Object, String) 일반적으로 정수(integer)를 반환합니다.