dataGridView添加按钮

 private void frmCheckoutList_Load(object sender, EventArgs e)
        {
            string sql = "select * from se_ClientInfo ";
            DataTable dt = SHIFT.GetDataTable(sql);
            this.dataGridView1.DataSource = dt;

            dataGridView1.Columns[0].HeaderText = "系统编号";
            dataGridView1.Columns[0].DataPropertyName = "InnerID";
            dataGridView1.Columns[0].Visible = false;
            #region 添加按钮

            /*添加按钮
            DataGridViewButtonColumn btnEdit = new DataGridViewButtonColumn();
            btnEdit.Name = "btnEdit";
            btnEdit.HeaderText = "编辑";
            btnEdit.Text = "编辑";
            btnEdit.Width = 50;
            btnEdit.UseColumnTextForButtonValue = true;
            dataGridView1.Columns.Insert(0, btnEdit);

            DataGridViewButtonColumn btnDel = new DataGridViewButtonColumn();
            btnDel.Name = "btnDel";
            btnDel.HeaderText = "删除";
            btnDel.Text = "删除";
            btnDel.Width = 50;
            btnDel.UseColumnTextForButtonValue = true;
            dataGridView1.Columns.Insert(1, btnDel);

            DataGridViewButtonColumn btnLog = new DataGridViewButtonColumn();
            btnLog.Name = "btnLog";
            btnLog.HeaderText = "记录";
            btnLog.Text = "记录";
            btnLog.Width = 50;
            btnLog.UseColumnTextForButtonValue = true;
            dataGridView1.Columns.Insert(2, btnLog);
             **/
            #endregion

            #region 图片
            ///* 图片
            DataGridViewImageColumn btnImageEdit = new DataGridViewImageColumn(false);
            Image imgEdit = new Bitmap(Properties.Resources.Save, new Size(16, 16));
            btnImageEdit.Image = imgEdit;
            btnImageEdit.Width = 50;
            btnImageEdit.HeaderText = "编辑";
            btnImageEdit.Name = "btnImageEdit";
            this.dataGridView1.Columns.Insert(0, btnImageEdit);

            DataGridViewImageColumn btnImageDel = new DataGridViewImageColumn(false);
            Image imgDel = new Bitmap(Properties.Resources.Delete, new Size(16, 16));
            btnImageDel.Image = imgDel;
            btnImageDel.Width = 50;
            btnImageDel.HeaderText = "删除";
            btnImageDel.Name = "btnImageEdit";
            this.dataGridView1.Columns.Insert(1, btnImageDel);

            DataGridViewImageColumn btnImageLog = new DataGridViewImageColumn(false);
            Image img = new Bitmap(Properties.Resources.Select,new Size(16,16));
            btnImageLog.Image = img;
            btnImageLog.Width = 50;
            btnImageLog.HeaderText = "记录";
            btnImageLog.Name = "btnImageLog";
            this.dataGridView1.Columns.Insert(2, btnImageLog);
            // * */
            #endregion 

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int CIndex = e.ColumnIndex;
            if (CIndex == 0)
            {
                FSTERP.Sell.frmClientInfo frm = new FSTERP.Sell.frmClientInfo();
                SHIFT.ShowFrm(frm, dataGridView1["InnerID", e.RowIndex].Value.ToString(), "客户详情");
            }
            else if (CIndex == 1)
            {
               if (MessageBox.Show("确认删除?", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes) 
                {
                    MessageBox.Show("删除!");
                }
            }
            else if (CIndex == 2)
            {
                FSTERP.Sell.frmClientRecord frm = new FSTERP.Sell.frmClientRecord();
                SHIFT.ShowFrm(frm, dataGridView1["InnerID", e.RowIndex].Value.ToString(), "客户记录");
            }
        }


你可能感兴趣的:(dataGridView添加按钮)