Binda.KeyValueListStrategy.SetControlValue C# (CSharp) Method

SetControlValue() public method

public SetControlValue ( Control control, object source, string propertyName ) : void
control System.Windows.Forms.Control
source object
propertyName string
return void
        public override void SetControlValue(Control control, object source, string propertyName)
        {
            ListControl listControl;
            PropertyInfo valueProperty;
            if ((listControl = control as ListControl) == null ||
                (valueProperty = source.GetType().GetProperty(propertyName)) == null)
            {
                return;
            }
            var value = valueProperty.GetValue(source, null);

            // DataSource == null; will reset the Display/Value Members...
            listControl.DataSource = GetCollection(source, propertyName, value);
            listControl.DisplayMember = "Value";
            listControl.ValueMember = "Key";

            listControl.SelectedValue = value;
        }