在gridview上右键,选择run designer
![图片[1]-DevExpress GridView添加按钮列-yiteyi-C++库](https://www.yiteyi.com/wp-content/uploads/2024/07/图片1.png)
![图片[2]-DevExpress GridView添加按钮列-yiteyi-C++库](https://www.yiteyi.com/wp-content/uploads/2024/07/图片2.png)
![图片[3]-DevExpress GridView添加按钮列-yiteyi-C++库](https://www.yiteyi.com/wp-content/uploads/2024/07/图片3.png)
//动态变换按钮类型
private void gridView2_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == “xxxx”)
{
if (gridView2.GetRowCellValue(e.RowHandle, “xxxx”).ToString() == “未绑定”)
{
repositoryItemButtonEdit2.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Plus;
}
else
{
repositoryItemButtonEdit2.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Clear;
}
}
}
private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (repositoryItemButtonEdit2.Buttons[0].Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
{
BindOrderToLine();
}
else
{
DeleteBindOrderToLine();
}
}
//按钮列中有多个按钮,根据点击不同的按钮,响应不同的事件
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
int index = gridView2.GetFocusedDataSourceRowIndex();//获取数据行的索引值,从0开始
if (index < 0)
{
return;
}
string orderID = gridView2.GetRowCellValue(index, “orderID”).ToString();
string lineName = gridView2.GetRowCellValue(index, “lineName”).ToString();
//
switch ( e.Button.Index )
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
暂无评论内容