开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 2774|回复: 1

gridview的表格按钮

[复制链接]

0

精华

19

贡献

352

赞扬

帖子
142
软币
1717
在线时间
183 小时
注册时间
2016-9-10
发表于 2018-5-24 09:50:12 | 显示全部楼层 |阅读模式
本帖最后由 1002068421 于 2018-5-24 09:59 编辑

固定列在哪里
设置Columns,选择要固定的列。设置Fixed属性,可以选择:固定在左边、固定在右边、不固定。

按图片选好按钮,然后设置Buttons下的属性   Kind = ButtonPredefines.Glyph;//初始的是有一个按钮
   Caption = str[0];
   Appearance.Options.UseForeColor = true;
   Appearance.ForeColor = Color.Pink;
  和选择的按钮属性
  btn.ButtonsStyle = BorderStyles.Default;
  btn.TextEditStyle = TextEditStyles.HideTextEditor;

  也可以自定义按钮
private RepositoryItemButtonEdit m_HandleBtn = new RepositoryItemButtonEdit();
初始化的时候设置按钮
List<string> str = new List<string>() { "查看资料", "处理" };
SetEditBtn(m_HandleBtn, str);

private void SetEditBtn(RepositoryItemButtonEdit btn, List<string> str)
        {
            for (int i = 0; i < str.Count(); i++)
            {
                btn.Buttons[0].Kind = ButtonPredefines.Glyph;//初始的是有一个按钮
                btn.Buttons[0].Caption = str[0];
                btn.Buttons[0].Appearance.Options.UseForeColor = true;
                btn.Buttons[0].Appearance.ForeColor = Color.Pink;
                if (i > 0)
                {
                    btn.Buttons.Add(new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph
                   , str, -1, true, true, false, DevExpress.XtraEditors.ImageLocation.MiddleCenter, null
                   , new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None)
                   , new DevExpress.Utils.SerializableAppearanceObject() { ForeColor = Color.Blue, Options = { UseBorderColor = true } }
                   , "", null, null, true));
                }
            //    btn.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            //new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph
            //    , "查看资料", -1, true, true, false, DevExpress.XtraEditors.ImageLocation.MiddleCenter, null
            //    , new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None)
            //    , new DevExpress.Utils.SerializableAppearanceObject(), "", null, null, true),
            //new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph
            //    , "处理", -1, true, true, false, DevExpress.XtraEditors.ImageLocation.MiddleCenter, null
            //    , new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None)
            //    , new DevExpress.Utils.SerializableAppearanceObject(), "", null, null, true)});  
            }
            btn.ButtonsStyle = BorderStyles.Default;
            btn.TextEditStyle = TextEditStyles.HideTextEditor;
        }


然后在事件添加按钮到表格
private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                if (e.Column.FieldName == "HandleBtn")
                {
                    e.RepositoryItem = m_HandleBtn;
                }
            }
            //if (e.Column.FieldName == "LookBtn")
            //{
            //    e.RepositoryItem = m_LookBtn;
            //}
        }
最后是注册按钮事件
this.m_HandleBtn.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(dgvBtns);
private void dgvBtns(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var SelectdeRow = gridView1.GetRow(gridView1.FocusedRowHandle) as system_oa_client_rec_error;
            if (SelectdeRow == null)
                return;
            if (e.Button.Index == 0)
            {
               //方法
            }
            if (e.Button.Index == 1)
            {
                //方法
            }
        }

最后一张图是效果图


选择buttonedit按钮

选择buttonedit按钮
2.png
回复

使用道具 举报

0

精华

0

贡献

0

赞扬

帖子
15
软币
95
在线时间
5 小时
注册时间
2018-7-26
发表于 2018-8-6 14:31:50 | 显示全部楼层
keyi的 牛皮
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-26 18:35

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表