标签:devexpress gridcontrol 按扭列 winform
为Winform 中的DevExpress GridControl某列添加按扭列,定义全局变量
RepositoryItemButtonEdit m_OperateFoodBtn = new RepositoryItemButtonEdit(); RepositoryItemButtonEdit m_OperateClothBtn = new RepositoryItemButtonEdit();
设置相关属性方法
private void SetEditBtn(RepositoryItemButtonEdit btn, string caption)
{ btn.Buttons[0].Kind = ButtonPredefines.Glyph; btn.Buttons[0].Caption = caption; btn.ButtonsStyle = BorderStyles.Simple; btn.TextEditStyle = TextEditStyles.HideTextEditor; }在加载时设置属性
protect override OnLoad(EventArgs e) { SetEditBtn(m_OperateFoodBtn,"试吃");
SetEditBtn(m_OperateClothBtn ,"试穿");}
注册GridView的gridView_CustomRowCellEdit事件
private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{ if (e.Column.FieldName != "OperateColumn") return; //可以根据某个值来判断用哪一按扭 DataRow row = gridView1.GetDataRow(e.RowHandle); if (row == null) return; if(row["ProductType"]=="Food") e.RepositoryItem = m_OperateFoodBtn ; else e.RepositoryItem = m_OperateCloseBtn ; }
点击按扭的相关操作
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { if (e.Column.FieldName != "OperateColumn") return; DataRow row = gridView1.GetDataRow(e.RowHandle); if (row == null) return; if(row["ProductType"]=="Food")//producttype为该行的其他数据列名 //操作食品 else //操作衣服 }
注意事项,在首次显示窗体时,要将Form的WindowState设为Normal,否则可能导致按扭不显示,原因不明,如果无此现象请略过。呵呵。。。。
标签:devexpress gridcontrol 按扭列 winform
原文地址:http://blog.csdn.net/blogtjf/article/details/45171291