title: Using threestate checkbox to determine 3 states of a field
body: <p>Currently we call a web service to check if user has permission to use the chat room and we receive a 0 or a 1. I want to add to also be able to receive a 2, which will indicate it is enabled and authorized now
  so I want to use three state check boxes, fully filled will mean he is authorized and also currently enabled (logged in), check will mean he is authorized but not enabled now, unchecked will mean he doesn't have permission for this chat room.</p>
  
  <p>Here is some code I currently use. FYI I took over this project from our developer and I'm kind of new to this, if you can give me an example even just for <code>authtac1</code> then I'll figure out how to do all others, and also do I need to add a new field <code>ActiveTac1</code> like I have <code>AuthTac1</code>?  Thanks for your help.</p>
  
  <pre><code>public partial class IMeditor : Form
  {
      private IMuser imu;
      private IMui IMui;
      private IMdata IMdata;
  
      public IMeditor(IMui IMui, IMuser U, string Member)
      {
          InitializeComponent();
          this.IMui= IMui;
          imu = U;
          if (imu.UID == 0)
          {
              Add.Text = "Add";
              imu.MemberNick= Member;
          }
          else
              Add.Text = "Update";
          IMdata = new IMdata();
          MemberHandle.Text = imu.MemberHandle;
          IM.Text = imu.IM;
          AuthChat.Checked = imu.AuthChat == 1;
          AuthTac1.Checked = imu.AuthTac1 == 1;
          AuthTac2.Checked = imu.AuthTac2 == 1;
          AuthTac3.Checked = imu.AuthTac3 == 1;
          AuthTac4.Checked = imu.AuthTac4 == 1;
  
  
  
          switch (imu.Transport.ToLower()) {
              case "aim":   Transport.SelectedIndex = 0; break;
              case "gtalk": Transport.SelectedIndex = 1; break;
              case "msn":   Transport.SelectedIndex = 2; break;
              case "yahoo": Transport.SelectedIndex = 3; break;
  
  }
  
  
  
      private void Add_Click(object sender, EventArgs e)
      {
          IMdata.AddIM(IMui.Username, IMui.Password, imu.UID, MemberHandle.Text, Transport.Text, IM.Text,
              AuthChat.Checked ? 1 : 0, 0, 
              AuthTac1.Checked ? 1 : 0, AuthTac2.Checked ? 1 : 0, AuthTac3.Checked ? 1 : 0,
              AuthTac4.Checked ? 1 : 0);
          Close();
      }
  </code></pre>
  
  <p><strong>last question, to make sure I didnt screw up anything else</strong>
  @competemt_tech this is what I ended up using (thanks so so much for your help, and our developer who was able to assist me)</p>
  
  <p>To know how to set the checkboxes when i get the data from the webservice I used</p>
  
  <pre><code> AuthChat.CheckState = GetCheckStateFromAuthCode(imu.AuthChat, imu.Enabled);
   AuthTac1.CheckState = GetCheckStateFromAuthCode(imu.AuthTac1, imu.Tac1Enabled);
   AuthTac2.CheckState = GetCheckStateFromAuthCode(imu.AuthTac2, imu.Tac2Enabled);
   AuthTac3.CheckState = GetCheckStateFromAuthCode(imu.AuthTac3, imu.Tac3Enabled);
  </code></pre>
  
  <p>and then I used:</p>
  
  <pre><code> private CheckState GetCheckStateFromAuthCode(int AuthCode, int Enabled)
      {
          switch (AuthCode + Enabled)
          {
              case 0:
                  return CheckState.Unchecked; // Unauthorized
              case 1:
                  return CheckState.Checked;  // Authorized, not enabled
              case 2:
                  return CheckState.Indeterminate; // Authorized and enabled
              default:
                  return CheckState.Unchecked;
          }
      }
  </code></pre>
  
  <p>and after I make changes, to send back to the webservice I used:</p>
  
  <pre><code>imu.AuthChat, imu.Enabled = GetAuthCodeFromCheckState(AuthChat.CheckState),
  imu.AuthTac1, imu.Tac1Enabled = GetAuthCodeFromCheckState(AuthTac1.CheckState),
  imu.AuthTac2, imu.Tac2Enabled = GetAuthCodeFromCheckState(AuthTac2.CheckState),
  imu.AuthTac3, imu.Tac3Enabled = GetAuthCodeFromCheckState(AuthTac3.CheckState),
  </code></pre>
  
  <p>and then I used:</p>
  
  <pre><code>private int GetAuthCodeFromCheckState(CheckState checkState)
      {
          switch (checkState)
          {
              case CheckState.Unchecked:  // Unauthorized
                  return 0;
              case CheckState.Indeterminate:  // Authorized, not enabled
                  return 1;
              case CheckState.Checked:  // Authorized and enabled
                  return 2;
              default:
                  return 0;
          }
      }
  </code></pre>