Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've edited my last project, showing no errors in code nor in run time.

it consists of two forms :

form1 is used to add a new object

Form1.cs
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace MobileCompany
{
    public partial class Form1 : Form
    {
        //At the start of the Application, we Create a New Company

     static public  List<SubcriberLine> Company = new List<SubcriberLine>();
       
        
        public Form1()
        {
            InitializeComponent();



        }
        

        private void button1_Click(object sender, EventArgs e)
        {
           //After Entering data into the fields, we Create an Cellphone Line Object 
            
                SubcriberLine s = new SubcriberLine(txtName.Text,txtNumber.Text,Convert.ToInt32(txtMobile.Text),
                    Convert.ToInt32(txtFixed.Text));
           
              
            //We Add the Cellphone Line Object to the Company's DataBase, Our Arraylist in our company MTN

                Company.Add(s);
           

            //confront the MTN Worker that the Adding process has been finished !

                MessageBox.Show("new CellPhone Line has been created !");
            
            



        }


        private void button2_Click(object sender, EventArgs e)
        {
            //In order to show all lines in Our company, we need to SHOW new table, new Page , or a new FORM
           
            Form2 f = new Form2();
            f.Show();
 
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


     }
    }


and by pressing buttom2, a new form , called Form2 is created and shown, this consists of only a DataGridView, and in each line it shows every object with detailed information, just as the following:

Form2.cs
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace MobileCompany
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

            for (int i = 0; i < Form1.Company.Count; i++)
            {
                dataGridView1.Rows.Add(Form1.Company[i].Identity,
                    Form1.Company[i].CustomerName, Form1.Company[i].MobileNumber);


  
            }
        }
    }

}


sadly, it's completely right thinking with the proper code-I guess; still, when running the application,pressing buttom2 to open the 2nd form with the DataGridView, it still can't show the current objects- which I've coded it to show.
Anyone can share and help, that's what coding is all about !
Posted
Comments
Jim Jos 17-May-12 8:33am    
Did you check Company has all objects?
obzajd 17-May-12 17:38pm    
company is just a list, so I can add objects to it.
and in form2, I'm just retrieving a property of an object I've already added it in form1.
I'm considering the key to the answer is by declaring a line (or column) as I've declared a DataGridView.Rows , but still can't find it logical or consistent if I started to think this way, or as saying: "outside the box"

1 solution

It's really shameful for the 52 persons who viewed my question was unable to solve a problem, that a rookie or a newbie like me has solved it on his own.

now the mistake I've thought about is, there's no rows without columns!

so, come to think of it, I needed a fixed columns with a columns' header name, and it should be written when the form loads, here Form2 loads :

Form2.cs

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
 
namespace MobileCompany
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
 
        private void Form2_Load(object sender, EventArgs e)
        {
            //the columms.Add Method takes only two strings, the 1st is          //a referral name, and the second is for the output name of the column 

            dataGridView1.Columns.Add("id","ID");
            dataGridView1.Columns.Add("customername","Customer Name");
            dataGridView1.Columns.Add("mobile","Mobile Number");

             //now we clear the Rows each time, so there would be no duplicates

            dataGridView1.Rows.Clear();

             //and here we start adding and stop till we reach the end of list.

            for (int i = 0; i < Form1.Company.Count; i++)
            {
                dataGridView1.Rows.Add(Form1.Company[i].Identity,
                    Form1.Company[i].CustomerName, Form1.Company[i].MobileNumber);
 

  
            }
        }
    }
 
}
 
Share this answer
 
v2

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