System.Windows.Forms.ComboBox.IsSelectedValueNull()

Here are the examples of the csharp api class System.Windows.Forms.ComboBox.IsSelectedValueNull() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Example 7

1. Example

Project: MiniMVP
Source File: ComboBoxExtensions.cs
View license
public static T GetSelectedValue<T>(this ComboBox cbo)
        {
            if (!cbo.IsSelectedValueNull())
            {
                if (cbo.SelectedValue.GetType() == typeof(T))
                    return (T)cbo.SelectedValue;
            }
            else if(cbo.SelectedItem != null && !cbo.ValueMember.IsNullOrWhiteSpace())
            {
                var pi = cbo.SelectedItem.GetType().GetProperty(cbo.ValueMember, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                if (pi != null && pi.PropertyType == typeof(T))
                    return (T)pi.GetValue(cbo.SelectedItem, null);
            }
            return default(T);
        }