DevExpress GridControl控件行内新增、编辑、删除添加选择框
以下为内容以图片居多1234表示点击顺序
先新增一行 操作和新增数据行一样
打开ColumnEdit 选择new ButtenEdit new上方会出现一个系统命名的button
命名可以更改必须在下发name中更改 是行的name
进入click事件就和普通的按钮一样了 可以编写自己的代码了
一下代码是设计器中的代码 供大家参考
// gridColumn_update this.gridColumn_update.Caption = "修改"; this.gridColumn_update.ColumnEdit = this.repositoryItemButtonEdit_update; this.gridColumn_update.FieldName = "gridColumn_update"; this.gridColumn_update.Name = "gridColumn_update"; this.gridColumn_update.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; this.gridColumn_update.Visible = true; this.gridColumn_update.VisibleIndex = 5; // // repositoryItemButtonEdit_update // this.repositoryItemButtonEdit_update.AutoHeight = false; serializableAppearanceObject1.Options.UseTextOptions = true; serializableAppearanceObject1.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near; this.repositoryItemButtonEdit_update.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), serializableAppearanceObject1, "", null, null, true)}); this.repositoryItemButtonEdit_update.Name = "repositoryItemButtonEdit_update"; this.repositoryItemButtonEdit_update.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor; this.repositoryItemButtonEdit_update.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(th.repositoryItemButtonEdit_update_ButtonClick);
DevExpress控件的属性太多了 还需要大家进行一步的学习使用理解
如有错误 或更好的方法 欢迎大家指指出
出处:https://blog.csdn.net/yueliangge910101/article/details/82257676
=================================================================
主要设置两个两个属性 NullText,Name
2.绑定数据
关键代码如下:
DataTable dt = dbHelp.GetDataSql("select TS_NO,TS_NAME ,TS_LONGITUDE,TS_LATITUDE,TS_RANK from dbo.LPTE_TS");
grStation.DataSource = null;
gvStation.Columns.Clear();
grStation.DataSource = dt;
gvStation.Columns["TS_NO"].Visible = false;
gvStation.Columns["TS_NAME"].Visible = true;
gvStation.Columns["TS_NAME"].Caption = "名称";
gvStation.Columns["TS_NAME"].VisibleIndex = 1;
gvStation.Columns["TS_RANK"].Visible = true;
gvStation.Columns["TS_RANK"].Caption = "等级";
gvStation.Columns["TS_RANK"].VisibleIndex = 2;
gvStation.Columns["TS_LONGITUDE"].Caption = "经度";
gvStation.Columns["TS_LATITUDE"].Caption = "纬度";
GridColumn addLinkHiper = new GridColumn();
addLinkHiper.Caption = "新增";
addLinkHiper.Visible = true;
addLinkHiper.ColumnEdit = stationAdd;
gvStation.Columns.Add(addLinkHiper);
addLinkHiper.VisibleIndex = 5;
GridColumn editLinkHiper = new GridColumn();
editLinkHiper.Caption = "编辑";
editLinkHiper.Visible = true;
editLinkHiper.ColumnEdit = stationEdit;
gvStation.Columns.Add(editLinkHiper);
editLinkHiper.VisibleIndex = 6;
GridColumn delLinkHiper = new GridColumn();
delLinkHiper.Caption = "删除";
delLinkHiper.Visible = true;
delLinkHiper.ColumnEdit = stationDel;
gvStation.Columns.Add(delLinkHiper);
delLinkHiper.VisibleIndex = 7;
gvStation.BestFitColumns();
以上数据已全部绑定完成
3.触发事件
在上图中点击事件Click,新增不多说,弹出新窗体即可
//编辑
private void stationEdit_Click(object sender, EventArgs e)
{
int[] selectRows = gvStation.GetSelectedRows();
//赋值
int tsNo = Convert.ToInt32(gvStation.GetRowCellValue(selectRows[0], "TS_NO")); //TS_NO是控件列名
//具体操作因人而异
......
}
//删除
private void stationDel_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定删除所选数据?", "删除提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
int[] selectRows = gvStation.GetSelectedRows();
//赋值
int tsNO = Convert.ToInt32(gvStation.GetRowCellValue(selectRows[0], "TS_NO"));
//写sql语句执行删除操作就可以了。
}
}
最后贴一张效果图:
出处:https://blog.csdn.net/m1654399928/article/details/21951519
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/10589639.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
posted on 2019-03-24 19:25 jack_Meng 阅读(3033) 评论(0) 编辑 收藏 举报