Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Toggle Y or N instead of TRUE or FALSE in texbox
Message
From
08/09/2008 09:42:44
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Toggle Y or N instead of TRUE or FALSE in texbox
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01345710
Message ID:
01345710
Views:
55
DISREGARD: Resolved. :)

First, a checkbox is a LAST RESORT. I am trying to emulate the foxpro toggling of values in .net

Ok, I have a textbox control that is used for a bit field in SQL Server (1 or 0) TRUE or FALSE. By default, the value is TRUE or FALSE. I want it to toggle between Y and N. I have that working using the keypress event. I am also changing the value in the _TextChanged() so that when data is first loaded, it displays Y instead of TRUE and N instead of FALSE. Both of those work fine.

Now, my problem is in saving the value. Obviously it raises an exception. How do I save TRUE instead of Y and FALSE instead of N? Where is the best place to put that code? For this form, values are saved when the control is exited, not using a save button.

Also, is the way I have done it so far ok? Is there a better way? Should the code below be some place else? I'm am not comfortable yet with which event runs when and where I would put code...
        private void txbisactive_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)32) 
            {
                if (((TextBox)sender).Text == "TRUE")
                {
                    ((TextBox)sender).Text = "N";
                }
                else
                {
                    if (((TextBox)sender).Text == "FALSE")
                    {
                        ((TextBox)sender).Text = "Y";
                    }
                    else
                    {
                        if (((TextBox)sender).Text == "Y")
                        {
                            ((TextBox)sender).Text = "N";
                        }
                        else
                        {
                            ((TextBox)sender).Text = "Y";
                        }
                    }
                }
            }
            else if (e.KeyChar == 'N' || e.KeyChar == 'n') 
            {
                  ((TextBox)sender).Text = "N"; 
            } 
            else if (e.KeyChar == 'Y' || e.KeyChar == 'y') 
            {
                  ((TextBox)sender).Text = "Y"; 
            } 
            e.Handled = true; 
        }
 
        private void txbisactive_TextChanged(object sender, EventArgs e)
        {
            if (((TextBox)sender).Text == "TRUE")
            {
                ((TextBox)sender).Text = "Y";
            }
            else
            {
                if (((TextBox)sender).Text == "FALSE")
                {
                    ((TextBox)sender).Text = "N";
                }
            }
        }
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Next
Reply
Map
View

Click here to load this message in the networking platform