小芸的功能里还有一个难点,在于就算用了CustomRowCellEdit事件来控制,但是因为她在那一格是没有数据的,所以如果需要对按钮设置,就必须得到那一行的数据,有这样一种思路:
private void grdvMain_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
if(e.Column==控件在的列)
{
if((this.GridView.GetRow(e.RowHandle) as MyDTO).MyAuttribute== MyValue ) //如果此行对应的DTO中的值为期望值
{
RepositoryItemButtonEdit button = new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit();
button.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
button.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
button.Click += new EventHandler(button_Click);
e.RepositoryItem = button;
RepositoryItemButtonEdit button = new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit();
button.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
button.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
button.Click += new EventHandler(button_Click);
e.RepositoryItem = button;
}
}
}
}
需要注意的是,如果绑定的是Data'Table类型,则上述不可转化,要用GetFocusRowData()