DataGridView单元格弹出窗体返回查询的值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/david_520042/article/details/6030838

        private void datagv_det_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            //获取品号相关信息按钮
            if (e.ColumnIndex.Equals(this.datagv_det.Columns["item"].Index))    //判断单元格是否是"item"列?
            {
                System.Windows.Forms.Button btn = new System.Windows.Forms.Button();//创建Buttonbtn
                btn.Text = "...";//设置button文字
                btn.Font = new System.Drawing.Font("Arial", 7);//设置文字格式
                btn.Visible = true;//设置控件允许显示

                btn.Width = this.datagv_det.GetCellDisplayRectangle(e.ColumnIndex,
                                e.RowIndex, true).Width/4;//获取单元格高并设置为btn的宽
                btn.Height = this.datagv_det.GetCellDisplayRectangle(e.ColumnIndex,
                                e.RowIndex, true).Height;//获取单元格高并设置为btn的高

                btn.Click += new EventHandler(btn_Click);//为btn添加单击事件

                this.datagv_det.Controls.Add(btn);//dataGridView1中添加控件btn


                btn.Location = new System.Drawing.Point(((this.datagv_det.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Right) -
                        (btn.Width)), this.datagv_det.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Y);//设置btn显示位置
         
            }

     }

 

        //自定义按钮事件
        private void btn_Click(object sender, EventArgs e)
        {

            frm_purchase_query form = new frm_purchase_query();
            form.toclose +=new dt(form_toclose);
            form.ShowDialog();
        }

 

        //调用事件处理
        private void form_toclose(string a,string b)
        {
            this.datagv_det.CurrentCell.Value = a;
            this.datagv_det.Rows[datagv_det.CurrentCell.RowIndex].Cells[datagv_det.CurrentCell.ColumnIndex + 1].Value = b;
        }

 

 

----新窗体---

namespace HR.SystemManage
{
    public partial class frm_purchase_query : Form
    {
        public event dt toclose;

        public frm_purchase_query()
        {
            InitializeComponent();     
        }

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

        private void frm_purchase_query_Load(object sender, EventArgs e)
        {

        }
    }
    public delegate void dt(string a,string b);
}

展开阅读全文

没有更多推荐了,返回首页