WINFORM - DevExpress -> 事件(gridcontrol)总结

1.RowCellStyle、RowStyle事件
gridview ---->变色_caoyanchao1的博客-CSDN博客

2.CustomColumnDisplayText

在gridview里面当是一个值的时候自动替换一个值

private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
     if (e.Column.FieldName == "dttime")//字段
     {
        if (e.DisplayText == "1900/1/1")//准备替换值
        {
           e.DisplayText = "";//替换后的值
        }
     }
}

3.CellvalueChanged,CellvalueChanging

DevExpress GridView单元格CellValueChanged事件详解|C/S框架网

DevExpress中的gridview中的cellvaluechanged事件(直接在表格内更新到数据库)

主表

private void advBandedGridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            GridView view = sender as GridView;
            //rowHandle的含义是获取定位编辑的单元格在第几行,可理解为Y坐标            
            int rowIndex = e.RowHandle;
            //获取被编辑的单元格在第几列,可理解为X坐标
            int columnindex = e.Column.AbsoluteIndex;
            //获取绑定到这个单元格的字段名
            string changeFiled = e.Column.FieldName;
            //获取被编辑的单元格的表头
            string caption = e.Column.Caption;
            //获取新输入的值
            string newValue = newValue = e.Value.ToString().Trim();
            string newid = advBandedGridView1.GetRowCellValue(rowIndex, "newId").ToString();
            bll.Update_2(changeFiled, newValue, newid);
        }

从表

private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.GridView currentView = (DevExpress.XtraGrid.Views.Grid.GridView)this.gridControl1.FocusedView;
            DataRow focusRow = currentView.GetFocusedDataRow();
            var newid = focusRow[0];
            var content1 = focusRow[1];
            bll.Update_2_1("content1", content1.ToString(), newid.ToString());
        }

fieldname字段循环的问题

4.ValidatingEditor事件

//gridcontrol输入验证
private void gdv_reguline_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{
    int col =((DevExpress.XtraGrid.Views.Grid.GridView)sender).FocusedColumn.AbsoluteIndex;
    if (col == 4 || col == 5)
    {
       object v = e.Value;
       int tm;
       if (v != null && (!Int32.TryParse(v.ToString(),out tm) || tm<0 )) //自定义验证逻辑
       {
            e.Valid = false; //控制是否通过验证的开关
            e.ErrorText = "必须输入正整数!"; //提示的验证失败的原因
       }
     }
 }

GridControl单元格验证_aa.a的博客-CSDN博客_gridcontrol 验证

相关链接

1.事件注册和注销

C#中的事件注册和注销 - 东郭西强 - 博客园

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
WinForm中,可以通过自定义单元格样式来实现GridControl中单元格文字的不同颜色或背景色。具体步骤如下: 1. 在GridControl的Properties窗口中找到Appearance属性,将其设为DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None,这样可以去掉单元格的焦点框。 2. 在GridControl上双击打开GridView的Designer界面。 3. 选中要修改样式的列,找到AppearanceCell属性,单击右侧的“...”按钮打开AppearanceObject对象的编辑器。 4. 在AppearanceObject编辑器中,可以设置字体、背景色、前景色等属性,还可以通过条件格式化来实现更复杂的样式。例如,可以在FormatConditions列表中添加条件格式化规则,然后在Appearance属性中设置对应的样式。 5. 保存样式后,关闭Designer界面即可看到效果。 下面是一段示例代码,演示如何在GridView中实现单元格文字颜色的动态变化: ```csharp private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (e.Column.FieldName == "Status") { string status = e.CellValue.ToString(); if (status == "OK") { e.Appearance.ForeColor = Color.Green; } else if (status == "Warning") { e.Appearance.ForeColor = Color.Yellow; } else if (status == "Error") { e.Appearance.ForeColor = Color.Red; } } } ``` 这段代码在GridView的CustomDrawCell事件中,判断当前单元格的列名是否为“Status”,如果是,则根据单元格的值来设置不同的字体颜色。可以根据自己的需求修改相应的代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fyhs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值