# [.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)
if (source.SupportsOne)

}



##### 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 on other sites
AHowell    128
Quote:
 Original post by RipTornyou 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 RipTornOr, 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 on other sites
RipTorn    722
yeah I was wasn't thinking for a moment there. You need to cast when dealing with value types.

## 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