Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1.Create a windows Form Application using Visual C#.Windows form consists of DataGridView and “Add Items” Button.
2.When Add Item button is clicked, the Information dialog box will come up and let the
visitor key in the information as shown.
3.After the user has key in the information of the dialog box, the information will be
Display on the DataGridView as shown.
4.All the data to be stored in the text file. The information can be read back and displayed while the application open again.

additional information copied from comment below
C#
//frm declaration

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

namespace Test
{
    public partial class FrmDeclaration : Form
    {
        public FrmDeclaration()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmDetails FrmDetails = new FrmDetails();
            FrmDetails.DetailUpdated += new FrmDetails.DetailUpdateHandler(DetailForm_ButtonClicked);
            FrmDetails.Show();
        }

        private void DetailForm_ButtonClicked(object sender, DetailUpdateEventArgs e)
        {
            dataGridView.ColumnCount = 8;
            dataGridView.Columns[0].Name = "NAME";
            dataGridView.Columns[1].Name = "NRIC";
            dataGridView.Columns[2].Name = "DATE";
            dataGridView.Columns[3].Name = "COMPANY";
            dataGridView.Columns[4].Name = "TELEPHONE";
            dataGridView.Columns[5].Name = "CONTACT PERSON";
            dataGridView.Columns[6].Name = "PURPOSE";
            dataGridView.Columns[7].Name = "ITEM";
        }
       
    }
}

//frmdetails

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

namespace Test
{
    public partial class FrmDetails : Form
    {
        public delegate void DetailUpdateHandler(object sender, DetailUpdateEventArgs e);

        public event DetailUpdateHandler DetailUpdated;

        public FrmDetails()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string sNewName = txtName.Text;
            string sNewNRIC = txtNRIC.Text;
            string sNewDate = txtDate.Text;
            string sNewCompany = txtCompany.Text;
            string sNewTel = txtTel.Text;
            string sNewContact = txtContact.Text;

            DetailUpdateEventArgs args = new DetailUpdateEventArgs(sNewName,
                sNewNRIC, sNewDate, sNewCompany, sNewTel, sNewContact);

            DetailUpdated(this, args);



            this.Dispose();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }

    public class DetailUpdateEventArgs : System.EventArgs
    {
        private string mNewName;
        private string mNewNRIC;
        private string mNewDate;
        private string mNewCompany;
        private string mNewTel;
        private string mNewContact;

        public DetailUpdateEventArgs(string sNewName, string sNewNRIC,
            string sNewDate, string sNewCompany, string sNewTel,
            string sNewContact)
        {
            this.mNewName = sNewName;
            this.mNewNRIC = sNewNRIC;
            this.mNewDate = sNewDate;
            this.mNewCompany = sNewCompany;
            this.mNewTel = sNewTel;
            this.mNewContact = sNewContact;
        }

        public string Name
        {
            get
            {
                return mNewName;
            }
        }

        public string NRIC
        {
            get
            {
                return mNewNRIC;
            }
        }

        public string Date
        {
            get
            {
                return mNewDate;
            }
        }

        public string Company
        {
            get
            {
                return mNewCompany;
            }
        }

        public string Tel
        {
            get
            {
                return mNewTel;
            }
        }

        public string Contact
        {
            get
            {
                return mNewContact;
            }
        }
    }
}

that my codes.. i got no idea why its not working
Posted
Updated 6-Oct-14 22:31pm
v2
Comments
VC.J 7-Oct-14 1:59am    
do you want to save this information(from dialogue box) in database.
If yes than you need to save the record in db and bind the grid with database.
Member 11134039 7-Oct-14 2:54am    
no im not using database. i want the form details to be in the datagridview
BillWoodruff 7-Oct-14 2:08am    
If we do your homework for you, you will learn nothing.
Nelek 7-Oct-14 4:09am    
This is not how CP usually works. Most important goal here is to learn and help learning.
You are supposed to try it on your own, and come here when you got stuck with something, with a concrete question about your code, design, etc.
Please have a look to What have you tried?[^] to see a good explanation about what I mean.
Don't forget people here don't get payed. And besides, if we give you a ready-to-go solution, it is not going to help you because you are not going to learn anything from it.
Member 11134039 7-Oct-14 4:12am    
//frm declaration

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

namespace Test
{
public partial class FrmDeclaration : Form
{
public FrmDeclaration()
{
InitializeComponent();
}

private void btnAdd_Click(object sender, EventArgs e)
{
FrmDetails FrmDetails = new FrmDetails();
FrmDetails.DetailUpdated += new FrmDetails.DetailUpdateHandler(DetailForm_ButtonClicked);
FrmDetails.Show();
}

private void DetailForm_ButtonClicked(object sender, DetailUpdateEventArgs e)
{
dataGridView.ColumnCount = 8;
dataGridView.Columns[0].Name = "NAME";
dataGridView.Columns[1].Name = "NRIC";
dataGridView.Columns[2].Name = "DATE";
dataGridView.Columns[3].Name = "COMPANY";
dataGridView.Columns[4].Name = "TELEPHONE";
dataGridView.Columns[5].Name = "CONTACT PERSON";
dataGridView.Columns[6].Name = "PURPOSE";
dataGridView.Columns[7].Name = "ITEM";
}

}
}

//frmdetails

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

namespace Test
{
public partial class FrmDetails : Form
{
public delegate void DetailUpdateHandler(object sender, DetailUpdateEventArgs e);

public event DetailUpdateHandler DetailUpdated;

public FrmDetails()
{
InitializeComponent();
}

private void btnOK_Click(object sender, EventArgs e)
{
string sNewName = txtName.Text;
string sNewNRIC = txtNRIC.Text;
string sNewDate = txtDate.Text;
string sNewCompany = txtCompany.Text;
string sNewTel = txtTel.Text;
string sNewContact = txtContact.Text;

DetailUpdateEventArgs args = new DetailUpdateEventArgs(sNewName,
sNewNRIC, sNewDate, sNewCompany, sNewTel, sNewContact);

DetailUpdated(this, args);



this.Dispose();
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.Dispose();
}
}

public class DetailUpdateEventArgs : System.EventArgs
{
private string mNewName;
private string mNewNRIC;
private string mNewDate;
private string mNewCompany;
private string mNewTel;
private string mNewContact;

public DetailUpdateEventArgs(string sNewName, string sNewNRIC,
string sNewDate, string sNewCompany, string sNewTel,
string sNewContact)
{
this.mNewName = sNewName;
this.mNewNRIC = sNewNRIC;
this.mNewDate = sNewDate;
this.mNewCompany = sNewCompany;
this.mNewTel = sNewTel;
this.mNewContact = sNewContact;
}

public string Name
{
get
{
return mNewName;
}
}

public string NRIC
{
get
{
return mNewNRIC;
}
}

public string Date
{
get
{
return mNewDate;
}
}

public string Company
{
get
{
return mNewCompany;
}
}

public string Tel
{
get
{
return mNewTel;
}
}

public string Contact
{
get
{
return mNewContact;
}
}
}
}

that my codes.. i got no idea why its not working

1 solution

try this
C#
private void button1_Click(object sender, EventArgs e)
        {
            grdView.Rows[0].Cells["textbox"].Value = textBox1.Text;
        }


here textbox is the name of the column

hope that will do for you
 
Share this answer
 
v2
Comments
Member 11134039 7-Oct-14 3:48am    
no its still not working

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