实现点击按钮控件时如果还要获取单元格的行 和列位置,那基本就是那需要使用系统指定的按钮列的实现方式实现.类似下边的代码

    //在datagridview中添加button按钮
            DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
            btn.Name = "Modify";
            btn.HeaderText = "操作";
            btn.DefaultCellStyle.NullValue = "修改";
            dataGridView1.Columns.Add(btn);

因为自己添加按钮后挡在单元格上边 ,无法获取到单元格的位置 所以详情那种按钮是无法使用的,有能使用的大师可以留言

但还有一种可以实现的方式就是先不显示按钮,等点击单元格的时候按钮 下拉框之类的显示出来,供用户选择,那类似详情的就不太适合了.

所以自己添加按钮的方式,适合那种链接之类的.  所以美丽的界面实现,却是是无用的,一步之遥,无法使用.....

   //添加
                dgv.Controls.Add(uISymbolButton);               

                //获取大小
                Rectangle rect = dgv.GetCellDisplayRectangle(columnIndex, rowIndex, true);
                //大小设置
                uISymbolButton.Size = new Size((rect.Width / 3), rect.Height);
                uISymbolButton.Size = new Size((rect.Width / 3), rect.Height);
                //  btn.Size = new Size((rect.Width / 3), rect.Height);

                //位置设置
                uISymbolButton.Location = new Point(rect.Left, rect.Top);             

                //绑定事件  
                uISymbolButton.Click += new EventHandler(detailsbtn_Click);/
  private void detailsbtn_Click(object sender, EventArgs E) //event of the control of the button added in the cell
        {
             var s= sender as UISymbolButton;
            var ss=  s.Parent as UISuperGrid;
            int ri= ss.CurrentCell.RowIndex;    //在此是无法获取到正确的 通过 获取parent 父的方式也是不行的,因为当前行还是默认的第一个行,按钮事件根本跟他没关系..............
           //These events can be increased according to business needs
        }

 

posted on 2022-10-14 09:30  小石头的一天  阅读(1256)  评论(0编辑  收藏  举报