none
Winform TextBox seems to ignore AcceptsReturn RRS feed

  • Question

  • I have a winform with tabpages with TextBoxs. The one TextBox that I was working on and vexing me has AcceptsTab=true, AcceptsReturn=true, Multiline, Scrollbars=Vertical, txtJ->DataBindings->Add(gcnew Binding("Text", BSJ, "Page", true)), Page is nvarchars(MAX), Data adapter, DataSet all working fine. In the same application I adding a Test tabPage and inserted TextBox with no bindings, and just like the bound TextBox, won't accept a return. A brand new winform with no bindings works fine with return. There are this->AcceptButton=nullptr in both. I tried Binding("Text", BSJ, "Page", false). I use a button "save" when clicked handles updates to DataTable and server because of columns created and modified being on server. What am I missing to get a return accepted in the text other than ctrl-enter?
    Monday, February 17, 2020 8:05 PM

Answers

  • The answer I added previously is wrong, being tested on an condensed sample. The correct answer is that in some manner I had mistaken what I had clicked on in the designer to add an event handler for a TabControl that should have only been assigned to an individual ComboBox on certain TabPages as needed. On the the TabPage that needed an AcceptReturn, it was being handled by the TabControl first. Solution is simply to keep looking for my own mistakes.

    • Marked as answer by mwindham Tuesday, February 18, 2020 7:59 AM
    • Unmarked as answer by mwindham Sunday, February 23, 2020 7:31 AM
    • Edited by mwindham Sunday, February 23, 2020 7:32 AM
    • Marked as answer by mwindham Sunday, February 23, 2020 7:36 AM
    Tuesday, February 18, 2020 5:07 AM

All replies

  • I am not sure if this is what you want, one button setup like yours, no data binding on the two TextBox controls, one is normal, the other multiline with your settings.

    namespace WindowsFormsApp3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                AcceptButton = button1;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Here");
            }
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                if (keyData == (Keys.Enter))
                {
                    /*
                     * textBox2 is setup like yours w/o data binding
                     */
                    if (ActiveControl.Name == "textBox2")
                    {
                        button1.PerformClick();
                        return true;
                    }
                }
    
                return base.ProcessCmdKey(ref msg, keyData);
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, February 17, 2020 9:14 PM
    Moderator
  • In an attempt to give as much info I had done, Irealize I was making what I wanted unclear. Everything works the way I intended except I can't type enter in the bound textbox and have it insert the enter. 

    As is, when I type enter, it goes to the first textbox on the tabPage. Something is messing up the AcceptsReturn. My button click handler private: System::Void btnJSave_Click(System::Object^ sender, System::EventArgs^ e) does what is needed. Ctrl-enter inserts a return.

    Monday, February 17, 2020 9:47 PM
  • The answer I added previously is wrong, being tested on an condensed sample. The correct answer is that in some manner I had mistaken what I had clicked on in the designer to add an event handler for a TabControl that should have only been assigned to an individual ComboBox on certain TabPages as needed. On the the TabPage that needed an AcceptReturn, it was being handled by the TabControl first. Solution is simply to keep looking for my own mistakes.

    • Marked as answer by mwindham Tuesday, February 18, 2020 7:59 AM
    • Unmarked as answer by mwindham Sunday, February 23, 2020 7:31 AM
    • Edited by mwindham Sunday, February 23, 2020 7:32 AM
    • Marked as answer by mwindham Sunday, February 23, 2020 7:36 AM
    Tuesday, February 18, 2020 5:07 AM
  • Hi mwindham,

    Thank you for posting here.

    Honestly, I'm a bit confused and I don't know how to start.

    Could you please provide a piece of code that can reproduce this problem? It will help us find and resolve the problem more quickly.

    Looking forward to your reply.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 18, 2020 5:59 AM