| |

VerySource

 Forgot password?
 Register
Search
View: 856|Reply: 7

Ask a form question ???

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-4 15:20:01
| Show all posts |Read mode
I have a ComBox control on the main form. I use the showDialog method to show a custom dialog box on the main form. There is a textBox control on it. I add data and activate a click event by clicking the "Finish" button. At the same time, a public method on the main form is called. This method mainly calls ComBox.Items.Add ("string").
But this did not achieve the effect I expected.

Excuse me, how can the data on the dialog box be transferred to the main form and added to the Items of comBox?
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-4 15:48:01
| Show all posts
Still didn't make it clear, that ComBox.Items.Add ("string"). It's ComBox.Items.Add (textBox.Text.ToString ()). The dialog's textBox
Reply

Use magic Report

0

Threads

10

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-4 17:45:02
| Show all posts
Please refer to
Easily master data interaction between Windows forms in .net
http://blog.csdn.net/Leng Yuxue / archive / 2004/04/05 / 22027.aspx
Form parameter passing
http://blog.csdn.net/Leng Yuxue / archive / 2006/05/05 / 708941.aspx # sec5
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-1-5 10:51:01
| Show all posts
With delegation ...

See also:
http://community.csdn.net/Expert/topic/5189/5189957.xml?temp=.6943018

The post I asked before asked "How to pass the values ​​in the subform to the ListView of the main form", the same reason ...
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-1-5 12:21:01
| Show all posts
Main form Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ComboboxTest
{
    // define a delegate
    public delegate void MyInvoke (string txt);
    public partial class Form1: Form
    {
        public Form1 ()
        {
            InitializeComponent ();
        }

        private void button1_Click (object sender, EventArgs e)
        {
            Form2 frm = new Form2 (new MyInvoke (UpdateCombobox));
            frm.ShowDialog (this);
        }
        private void UpdateCombobox (string txt)
        {
            //Add to
            this.comboBox1.Items.Add (txt);
            // Select the newly added item
            this.comboBox1.SelectedIndex = this.comboBox1.Items.Count-1;
        }
    }
}


Subform Form2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ComboboxTest
{
    public partial class Form2: Form
    {
        private MyInvoke mi = null;
        public Form2 (MyInvoke myInvoke)
        {
            InitializeComponent ();
            mi = myInvoke;
        }

        private void button1_Click (object sender, EventArgs e)
        {
            this.mi (this.textBox1.Text.Trim ());
            this.Close ();
        }
    }
}

For a detailed explanation, please see the original post ..
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-5 15:54:01
| Show all posts
Thank you very much for the answers, but what is the reason why my method is not successful?
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-1-5 16:18:01
| Show all posts
How about you call that method on the main form?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 13:33:01
| Show all posts
A value on the subform (dialog) should be passed back to the caller as public
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list