Hello,

I have several textboxes and it is possible to write something in one of them and then without losing the focus I could or would save the input. But there is no FocusLost and therefore the TextChanged event doesn't fire.

How can I save the input of one these textboxes if enter or tab isn't pressed?

Thanks for help

id look into Key events i guess but it will fire the saves multiple times since you can't really know when hes done typing if you dont lose focus?

just a thought!
Good Luck

While there isn't a focuslost event there is a lostfocus event. Tha handler is like this:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.textBox1.LostFocus += new System.EventHandler(this.textBox1_LostFocus);            
        }

        private void textBox1_LostFocus(object sender, EventArgs e)
        {

        }
    }

How are you coding the textchanged event handler? it doesn't rely on the lostfocus event. Your code should follow the same pattern, change the Lostfocus to TextChanged.

BTW In C# you can find all the events available to a control by using Intellisense. When you type, for example, TextBox1. everything in the list that Intellisense shows you, with a lightning bolt icon, is an event and can be handled.

I read that the textChanged event fires when the control loses the focus. And yes. First I wrote my code in the lostFocus event, but I want to ensure that the input is saved if the focus is not lost. Therefore I changed lostFocus in textChanged. And this is the code in the textChanged handler:

private void textStartI_TextChanged(object sender, EventArgs e)
{
    String inputValue = commaInPoint(textStartI.Text);

    // Try -> catch if a key, which is not a number, is used.
    try
    {
        selectedMeasurement.InnerSweepStart = Convert.ToDouble(inputValue);

        if (selectedMeasurement.SelectedInnerSweep == "Gate Bias")
        {
            chosenGate = (SourceMeter)selectedMeasurement.GateBiasSel;
            chosenGate.Voltage = selectedMeasurement.InnerSweepStart;
        }

        else if (selectedMeasurement.SelectedInnerSweep == "Drain Bias")
        {

            chosenDrain = (SourceMeter)selectedMeasurement.DrainBiasSel;
            chosenDrain.Voltage = selectedMeasurement.InnerSweepStart;
        }

    }

    catch (ArgumentOutOfRangeException ex)
    {
        MessageBox.Show(this, ex.ParamName + "\nPlease enter a possible value.", "Out of range");
        textStartI.SelectAll();
        textStartI.Focus();
    }

    catch (FormatException)
    {
        MessageBox.Show(this, letter.Message, "Error");
        textStartI.SelectAll();
        textStartI.Focus();
    }



    if (selectedMeasurement.check())
    {
        buttonStart.Enabled = true;
    }
    else
    {
        buttonStart.Enabled = false;
    }

    richTextStatusUp.Text = selectedMeasurement.CheckString;
}

I don't know if you can solve the problem by looking at the code, but I thought that I can use the textChanged event for my idea (if the textbox doesn't lose focus, that it's able to save the input) and yes, I know intellisense...Thanks :)

I think my problem is solved. I forgot to add the Eventhandler for the textChanged Event. Thank you so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.