• Advertisement
Sign in to follow this  

[.net] [MDX]DeviceCaps to a ComboBox

This topic is 4291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
yeah I was wasn't thinking for a moment there. You need to cast when dealing with value types.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement