BindingGroup.GetValue(Object, String) Yöntem

Tanım

Belirtilen özellik ve öğe için önerilen değeri döndürür.

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

Parametreler

item
Object

Belirtilen özelliği içeren nesne.

propertyName
String

Elde etmek için önerilen değeri olan özellik.

Döndürülenler

Object

Önerilen özellik değeri.

Özel durumlar

Belirtilen öğe ve özellik için bağlama yok.

Belirtilen özelliğin değeri, dönüştürme hatası nedeniyle veya önceki bir doğrulama kuralı başarısız olduğundan kullanılamıyor.

Örnekler

Aşağıdaki örnek, kullanıcıdan birden çok müşteri girmesini ve her müşteriye bir satış temsilcisi atamasını isteyen bir uygulamanın parçasıdır. Uygulama, satış temsilcisiyle müşterinin aynı bölgeye ait olup olmadığını denetler. Örnekte, müşterinin girdiği değerleri almak için yöntemini kullanan GetValue(Object, String) yöntemi gösterilmektedirValidate.

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

Açıklamalar

Kaynağa işlenecek değeri almak için yönteminde bu yöntemi ValidationRule.Validate kullanın. Dönüş değerinin türü, değerinin gerçekleştiği aşamaya ValidationRule bağlıdır. Örneğin, bir TextBox tamsayı türündeki bir özelliğe bağlı bir veriyse ve çağrıları ValidationStep ValidationRule GetValue(Object, String) olarak ayarlanmışsaRawProposedValue, yöntem bir dize döndürür. ValidationRule ValidationStep olarak ayarlandıysaConvertedProposedValue, yöntemi bağlamanın dönüştürücüsü tarafından döndürülen türü döndürür. Bu örnekte, GetValue(Object, String) genellikle bir tamsayı döndürür.

Şunlara uygulanır