1.DataGridView所在的窗体

//变量
        public delegate void GetDgRow(DataGridViewSelectedRowCollection rows);
        public virtual event GetDgRow EventShowRow;
//DataGridView 事件
#region
单击选择 private void dgvParent_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) return; if (e.ColumnIndex == 0) { this.dgvParent["选择", e.RowIndex].Value = (this.dgvParent["选择", e.RowIndex].Value == null || this.dgvParent["选择", e.RowIndex].Value.ToString().ToLower() == "false") ? true : false; dgvParent.EndEdit(); } } #endregion #region 快速选择 /// <summary> ///快速选择 ///Author: ///WriteTime: 2014-01-22 23:49:40 /// </summary> protected override void QuickSelect() { try { int currentindex = dgvParent.CurrentRow.Index; dgvParent.CurrentCell = null; dgvParent.Rows[currentindex].Selected = true; if (EventShowRow != null) { foreach (DataGridViewRow dr in dgvParent.Rows) { //判断选择行的选中状态,设置行是否是选中的。 if (dr.Cells["选择"].Value == null || dr.Cells["选择"].Value.ToString() == "False") continue; dr.Selected = true; } DataGridViewSelectedRowCollection rows = dgvParent.SelectedRows; EventShowRow(rows); this.Close(); } } catch (Exception ex) { Msg.InfoBox(ex.Message); } } #endregion

2.需要弹框选择的窗体-按钮事件

#region 选择产品
        private void txtProductNo_ButtonCustomClick(object sender, EventArgs e)
        {
            FrmProduct frm = new FrmProduct();
            frm.EventShowRow += new FrmProduct.GetDgRow(frm_EventShowRow);
            frm.Show();
        }

        void frm_EventShowRow(DataGridViewSelectedRowCollection row)
        {
            this.txtProductNo.Tag = row[0].Cells["_AutoID"].Value.ToString();
            this.txtProductNo.Text = row[0].Cells["STRITEMCODE"].Value.ToString();
        }
        #endregion
posted on 2014-07-16 15:24  清风暮雨  阅读(265)  评论(0)    收藏  举报