Sign in to follow this  
AHowell

[.net] [MDX]DeviceCaps to a ComboBox

Recommended Posts

AHowell    128
Is there an easier way of converting a DeviceCaps struct into a combo box, than by checking each one in the list to see if it is true? Currently I am using this :
void FillComboSource(BlendCaps source)
        {
            int index = 0;
            if (source.SupportsZero)
                combo_SourceBlend.Items.Add("Zero");
            if (source.SupportsOne)
                combo_SourceBlend.Items.Add("One");

        }

Share this post


Link to post
Share on other sites
RipTorn    722
you can use reflection to get all the public properties inside the class, get their values, etc.


Type t = source.GetType();

PropertyInfo[] properties = t.GetProperties();

foreach (PropertyInfo p in properties)
{
if ((p.GetValue(source,null) is bool) &&
(p.GetValue(source,null) as bool) == true)
combo_SourceBlend.Items.Add(p.Name);
}


Or, you could also use a PropertyGrid instead of a combo box. Simply set it's 'SelectedObject' property to your BlendCaps object (or you DeviceCaps object to show everything).

Share this post


Link to post
Share on other sites
AHowell    128
Quote:
Original post by RipTorn
you can use reflection to get all the public properties inside the class, get their values, etc.



Type t = source.GetType();

PropertyInfo[] properties = t.GetProperties();

foreach (PropertyInfo p in properties)
{
if ((p.GetValue(source,null) is bool) &&
(p.GetValue(source,null) as bool) == true)
combo_SourceBlend.Items.Add(p.Name);
}






Tried this above and got an error with using "as" incorrectly, which led me to trying this below.

EDIT: error message "The as operator must be used with a reference type ('bool' is a value type)"

Quote:
Original post by RipTorn
Or, you could also use a PropertyGrid instead of a combo box. Simply set it's 'SelectedObject' property to your BlendCaps object (or you DeviceCaps object to show everything).


And boy is it pretty. Now I just need to fiddle with it's sizing and selection properties.

Thanks for the info.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this