Click here to Skip to main content
15,938,446 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello every one.
i need simple help.
in my C# desktop application,
i create one form name students master form in which insert student name in textbox, student address in textbox and contact no in textbox.
now when i click save button it save data in database table and also dispaly in datagridview in same form.

now i create another school master form. so need student master form's count how may rows inserted.
i get count row.
but don't know how to pass int another form that count variable.

What I have tried:

int counter=datagridview.rows.count

above int counter i get datagrid actual rows.

but how can i use that int counter in another form in c#
Posted
Updated 8-May-17 4:10am
Comments
Ralf Meier 8-May-17 10:02am    
The issue you described sounds like a Dialog for me.
So you should create your own custom Dialog and give it all data which is needed.
After editing you come back from the Dialog with a DialogResult which tells your calling Form what should be done with the data ...

Form 1

on Button Click Event

C#
private void button1_Click(object sender, EventArgs e)
       {
           Form2 abc = new Form2(Convert.ToInt16(comboBox1.SelectedValue));
           abc.Show();
       }


Form 2

Create new Constructor For Same name of Form

C#
public Form2()
        {
            InitializeComponent();
        }
        public Form2(int ab)
        {
            InitializeComponent();
            textBox1.Text = ab.ToString();
        }
 
Share this answer
 
OriginalGriff has written a series of Tips on how to pass information between forms. The first one is here Transferring information between two forms, Part 1: Parent to Child[^] and there are links to the others within that article.

When getting integer values from strings use int.Parse or int.TryParse instead of Convert.ToInt16. See Dotnetperls examples[^] The TryParse methods will not raise an exception, unlike Convert.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900