zoukankan      html  css  js  c++  java
  • Dev中GridView——事件

     gridControl下的事件一般是包含View切换,点击,更改事件,用的不多。而每一个View下的事件我们却常用到。

    GridView中事件:

         GridView中大多数事件都会用到e这个参数,从e这个参数中我们可以获取很多信息。e是根据事件来定义级别的,可以获取e的层级以上的信息,但不能获取e的层及以下的信息。

    1、CustomDrawEmptyForeground(自定义绘制空白前景):当没有显示任何行时,允许对视图的空间进行自定义绘制。
    1.  
      private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
    2.  
      {
    3.  
      string txt = "空白!";
    4.  
      Font font = new Font("宋体", 20, FontStyle.Bold);
    5.  
      e.Graphics.DrawString(txt, font, Brushes.Purple, e.Bounds.Top + 200, e.Bounds.Left + 200);
    6.  
      //BindingSource bindingsource = this.gridView1.DataSource as BindingSource; //封装窗体的数据源
    7.  
      //if (bindingsource == null)
    8.  
      //{
    9.  
      // string txt = "空白!";
    10.  
      // Font font = new Font("宋体", 20, FontStyle.Bold);
    11.  
      // //存储一组整数,共四个,表示一个矩形的位置和大小。Rectangle(int x, int y, int width, int height);
    12.  
      // //参数为:矩形左上角的 x 坐标。矩形左上角的 y 坐标。矩形的宽度。矩形的高度。
    13.  
      // Rectangle r = new Rectangle(e.Bounds.Top+200, e.Bounds.Left+200,e.Bounds.Right, e.Bounds.Height);
    14.  
      // e.Graphics.DrawString(txt, font, Brushes.Purple, r);
    15.  
      //}
    16.  
      }
    2、CellMerge(单元格合并):提供自定义单元合并行为的功能。需先设置gridView1.OptionsView.AllowCellMerge = true;
    1.  
      private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
    2.  
      {
    3.  
      if (e.Column.FieldName != "Name")
    4.  
      e.Handled = true; //获取或设置是否处理单元格合并操作,因此不需要进行默认处理。
    5.  
      }
    3、CustomColumnDisplayText(自定义列显示):为数据单元格内的值、组行和过滤下拉菜单自定义显示文本

        gridControl的每一列原始数据是Value,但是显示数据是DisplayText,默认DisplayText的值即是Value通过DisplayFormat转换后的值。

    1.  
      private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
    2.  
      {
    3.  
      if (e.Column.FieldName == "Data")
    4.  
      {
    5.  
      string a = Convert.ToInt16(e.Value) < 0 ? "负数" : "正数"; //是否为正数
    6.  
      switch(a)
    7.  
      {
    8.  
      case "负数":
    9.  
      e.DisplayText = "负数据";
    10.  
      break;
    11.  
      case"正数":
    12.  
      e.DisplayText = "正数据";
    13.  
      break;
    14.  
      }
    15.  
      }
    16.  
      }
    4、CustomDrawGroupRow(自定义绘制组行):允许手动绘制组行
    1.  
      private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
    2.  
      {
    3.  
      GridGroupRowInfo gridGroupRowInfo = e.Info as GridGroupRowInfo;
    4.  
      gridGroupRowInfo.GroupText = "第" + (e.RowHandle) + "行" + gridGroupRowInfo.EditValue;
    5.  
      }
    5、CustomDrawRowIndicator(自定义行号显示):能够自定义绘制行指示器面板中的元素。需先设置行指示面板宽度gridView1.IndicatorWidth = 70; 
    1.  
      private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
    2.  
      {
    3.  
      if (e.Info.IsRowIndicator)
    4.  
      {
    5.  
      e.Info.DisplayText = "Row" + e.RowHandle;
    6.  
      }
    7.  
      }
    6、RowCellClick(单元格点击事件):如果数据是可编辑的,事件将不会触发
    1.  
      private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
    2.  
      {
    3.  
      if (e.Button == MouseButtons.Left) //鼠标左键
    4.  
      {
    5.  
      //执行的方法
    6.  
      }
    7.  
      if (e.Clicks == 2) //双击
    8.  
      { }
    9.  
      if (e.Delta > 0)//鼠标滚轮滚动方向
    10.  
      { }
    11.  
      if (e.X > 0 & e.Y > 0)//鼠标的坐标
    12.  
      { }
    13.  
      if (e.RowHandle > 0) //点击的行号
    14.  
      { }
    15.  
      if (e.CellValue != null)//点击的单元格中的值
    16.  
      { }
    17.  
      if (e.Column != null)//点击的单元格所属列的信息
    18.  
      { }
    19.  
      }
    7、RowClick(行点击事件):如果点击数据是可编辑的,事件将不会触发
    1.  
      private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
    2.  
      {
    3.  
      if (e.Clicks == 2) //双击
    4.  
      { }
    5.  
      }
    8、CustomDrawCell(重绘列样式):自定义绘制数据单元格
    1.  
      private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
    2.  
      {
    3.  
      if (e.Column.Caption == "数据")
    4.  
      {
    5.  
      GridCellInfo gridCellInfo = e.Cell as GridCellInfo;
    6.  
      if (gridCellInfo.IsDataCell && double.Parse(gridCellInfo.CellValue.ToString()) < 0)
    7.  
      {
    8.  
      e.Appearance.BackColor = Color.Yellow;
    9.  
      }
    10.  
      else { e.Appearance.BackColor = Color.Green; }
    11.  
      }
    12.  
      }
    9、CalcPreviewText(自定义备注):自定义备注文本 需先设置gridView1.OptionsView.ShowPreview = true;
    1.  
      private void gridView1_CalcPreviewText(object sender, DevExpress.XtraGrid.Views.Grid.CalcPreviewTextEventArgs e)
    2.  
      {
    3.  
      DataRow dr = gridView1.GetDataRow(e.RowHandle);
    4.  
      e.PreviewText = dr["Name"] + ":" + dr["Sex"];
    5.  
      }
    10、RowCellStyle(定制单元格外观):允许单个单元格的外观设置得以更改
    1.  
      private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
    2.  
      {
    3.  
      //GridView View = sender as GridView;
    4.  
      if (e.Column.FieldName == "Age" || e.Column.FieldName == "Data")
    5.  
      {
    6.  
      //string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Category"]);
    7.  
      string category = gridView1.GetRowCellDisplayText(e.RowHandle, gridView1.Columns["Name"]);
    8.  
      if (category == "张三")
    9.  
      {
    10.  
      e.Appearance.BackColor = Color.DeepSkyBlue;
    11.  
      e.Appearance.BackColor2 = Color.LightCyan;
    12.  
      }
    13.  
      }
    14.  
      }
    11、RowStyle(定制行外观):允许更改各行的外观设置
    1.  
      private void gridView1_RowStyle(object sender, RowStyleEventArgs e)
    2.  
      {
    3.  
      GridView View = sender as GridView;
    4.  
      if (e.RowHandle >= 0)
    5.  
      {
    6.  
      string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Name"]);
    7.  
      if (category == "张三")
    8.  
      {
    9.  
      e.Appearance.BackColor = Color.DeepSkyBlue;
    10.  
      e.Appearance.BackColor2 = Color.SeaShell;
    11.  
      }
    12.  
      }
    13.  
      }
    12、MasterRowGetRelationCount(主行获取关系数目):接管此事件来为每个主控行指定主/从关系的数目
    1.  
      private void gridView1_MasterRowGetRelationCount(object sender, MasterRowGetRelationCountEventArgs e)
    2.  
      {
    3.  
      e.RelationCount = 1; //显示1个关系,若设置为非正数则展开按钮被隐藏
    4.  
      }
    13、MasterRowEmpty(指定当前细节视图是否有数据):允许指定细节是否为空
    1.  
      private void gridView1_MasterRowEmpty(object sender, MasterRowEmptyEventArgs e)
    2.  
      {
    3.  
      int a = e.RowHandle;//获取主控行的 句柄 由事件的 RowHandle 参数标识
    4.  
      int b = e.RelationIndex; //获取引用当前细节数据的 RelationIndex 参数
    5.  
      e.IsEmpty = false; //展示数据
    6.  
      }
    14、MasterRowGetChildList(接管此事件来为当前细节视图提供数据):允许手动加载细节数据
    1.  
      private void gridView1_MasterRowGetChildList(object sender, MasterRowGetChildListEventArgs e)
    2.  
      {
    3.  
      //
    4.  
      }
    15、MasterRowGetRelationName(接管此事件为当前关系 (细节) 提供名称):允许使用指定的细节视图 。需先构建GridControl.LevelTree 树
    1.  
      private void gridView1_MasterRowGetRelationName(object sender, MasterRowGetRelationNameEventArgs e)
    2.  
      {
    3.  
      e.RelationName = "关系";
    4.  
      }
    16、MasterRowGetLevelDefaultView():允许使用指定细节模式视图
         接管此事件来为当前呈现的细节视图显式提供模式视图。 通常,如果所需的模式视图不属于 GridControl.LevelTree 树,则需要接管此事件。 否则,在大多数情况下,可以通过 GridView.MasterRowGetRelationName 事件间接提供模式视图。
    1.  
      private void gridView1_MasterRowGetLevelDefaultView(object sender, MasterRowGetLevelDefaultViewEventArgs e)
    2.  
      {
    3.  
      //
    4.  
      }
     
     
    一般属性设置 不显示分组框:Gridview->Option View->Show Group Panel=false 单元格不可编辑:gridcontrol -->gridview -->OptionsBehavior -->Editable=false 禁用过滤器:Run Design->OptionsCustomization->AllowFilt...
    Devexpress GridView 数据格式化显示 gridView1.CustomColumnDisplayText += gridView1_CustomColumnDisplayText; void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomC...

    通常我们在写主题程序或者新闻的程序中..字符太多了需要处理。使用substring()函数处理一下的  所以我想到写一公共函数:    #region //主题格式    ///     /// 功能: 设置显示格式: 主题+...    /// 创建时间:2008-12-18    /// 创建人:龚德辉    ///     /// 传入的参数    /// 显示的长度  
    目标窗体的表格控件不要使用CustomColumnDisplayText,CustomDrawCell等自定义事件 转载于:https://www.cnblogs.com/tian2008/p/8191387.html
    dev GridView常用属性,事件_weixin_30505485的博客-CSDN博客
    10-28
    dev GridView常用属性,事件 一、属性 1、GridControl属性 //允许拖拽行gridControl1.AllowDrop =true; 2、GridView属性 //不可编辑gridView1.OptionsBehavior....
    Dev中GridControl中点击事件_漓涂-CSDN博客
    10-24
    gridView 行点击事件: private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { System.Data.DataRowView pDataRow...
    protected void ASPxGridView1_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) { if (e.Column.VisibleIndex == 8) ...
    原始数据格式:下面要求把“数据”设置为保留2位小数,日期显示至秒。    运行结果:
    DevExpress GridView使用以及按钮列事件问题_qq_176140..._CSDN博客
    11-11
    左侧栏下边有个Repository,如图选择,最后找到ButtonClike,点击即可获取事件。 6.事件中获取行对象核心代码: GridView view = ((GridView)(this.gridControl2.MainVie...
    DevExpress GridControl中gridview单元格点击事件(获取..._CSDN博客
    11-8
    this.repositoryItemCheckEdit1.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.InactiveChecked; this.gridView1.SetRowCellValue(selectRow, "IsStart"...
    一般设置为:gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; //列头居中 gridView1.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center...
    DevExpress.XtraGrid.Views 设置指定行的背景颜色 1.事件:CustomDrawCell2.示例:private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if ...
    dev 实现三层GridView嵌套并有点击事件_育苗小工的博客-CSDN博客
    9-12
    privatevoidgv1_RowClick(objectsender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { //GridView using DevExpress.XtraGrid.Views.Grid ...
    关于DevExpress GridControl中gridView1_InitNewRow事..._CSDN博客
    11-6
    private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e) { MessageBox.Show("触发事件测试"); ...
    数据准备:自义定一个DataTable作为GridControl的数据源。private DataTable CreatDataTable() { DataTable dt = new DataTable();//创建表 DataColumn dc = new DataColumn(); dc.Caption = "编号"; dc.ColumnName = "I...
    支持本地书签、tab页、历史记录搜索;
  • 相关阅读:
    使用math.js进行javascript精确计算
    SpringMVC java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name
    MAC系统下配置环境变量
    javaURL中文乱码的问题
    Mac系统搭建java开发环境
    mysql 删除重复数据保留只保留一条
    SSM 加载配置文件
    CSS3实现元素旋转
    CSS3实现圆角效果
    CSS3 -web-box-shadow实现阴影效果
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/14017794.html
Copyright © 2011-2022 走看看