如何在表单中添加详细信息然后将详细信息传输到Datagridview [英] How Do I Add Details Inside A Form And Then Transfer The Details Into Datagridview

查看:100
本文介绍了如何在表单中添加详细信息然后将详细信息传输到Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.使用Visual C#创建一个Windows窗体应用程序.Windows窗体由DataGridView和添加项目按钮组成。

2.单击添加项目按钮时,将出现信息对话框并让

访问者键入所显示的信息。

3.用户输入对话框信息后,信息将是

显示在DataGridView上,如图所示。

4.所有数据都存储在文本文件中。当应用程序再次打开时,可以回读和显示这些信息。



从下面的评论中复制的其他信息

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

//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

推荐答案

试试这个

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





这里textbox是列的名称



希望能为你做什么



here textbox is the name of the column

hope that will do for you


这篇关于如何在表单中添加详细信息然后将详细信息传输到Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆