BrightIdeasSoftware.ObjectListView.SetControlValue C# (CSharp) Method

SetControlValue() protected method

Try to give the given value to the provided control. Fall back to assigning a string if the value assignment fails.
protected SetControlValue ( Control control, Object value, String stringValue ) : void
control Control A control
value Object The value to be given to the control
stringValue String The string to be given if the value doesn't work
return void
        protected virtual void SetControlValue(Control control, Object value, String stringValue)
        {
            // Handle combobox explicitly
            if (control is ComboBox) {
                ComboBox cb = ((ComboBox)control);
                if (cb.Created)
                    cb.SelectedValue = value;
                else
                    this.BeginInvoke(new MethodInvoker(delegate {
                        cb.SelectedValue = value;
                    }));
                return;
            }

            if (Munger.PutProperty(control, "Value", value))
                return;

            // There wasn't a Value property, or we couldn't set it, so set the text instead
            try {
                String valueAsString = value as String;
                if (valueAsString == null)
                    control.Text = stringValue;
                else
                    control.Text = valueAsString;
            } catch (ArgumentOutOfRangeException) {
                // The value couldn't be set via the Text property.
            }
        }
ObjectListView