How can I make a Yes/No combobox return true/false?
        Posted  
        
            by 
                Kasper Hansen
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Kasper Hansen
        
        
        
        Published on 2010-11-25T08:46:03Z
        Indexed on 
            2011/01/14
            17:54 UTC
        
        
        Read the original article
        Hit count: 336
        
I am new to creating forms in Visual Studio and C#. But I made a UI that has some comboboxes where the DropDownStyle is DropDownList. The items shown is Yes and No. But I need to assign this as a boolean value to a property on some object ai and currently do this:
    if (cmbExample.Text == "Yes")
    {
        ai.isPacketType = true;
    }
    else if (cmbExample.Text == "No")
    {
        ai.isPacketType = false;
    }
I basically want to do something like this (or some other one liner):
ai.isPacketType = cmbExample.Text;
How do I link the Text Yes to the value true and No to false?
© Stack Overflow or respective owner