gridControl下的事件一般是包含View切换,点击,更改事件,用的不多。而每一个View下的事件我们却常用到。
GridView中事件:
GridView中大多数事件都会用到e这个参数,从e这个参数中我们可以获取很多信息。e是根据事件来定义级别的,可以获取e的层级以上的信息,但不能获取e的层及以下的信息。
1、CustomDrawEmptyForeground(自定义绘制空白前景):当没有显示任何行时,允许对视图的空间进行自定义绘制。
-
private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
-
{
-
string txt = "空白!";
-
Font font = new Font("宋体", 20, FontStyle.Bold);
-
e.Graphics.DrawString(txt, font, Brushes.Purple, e.Bounds.Top + 200, e.Bounds.Left + 200);
-
//BindingSource bindingsource = this.gridView1.DataSource as BindingSource; //封装窗体的数据源
-
//if (bindingsource == null)
-
//{
-
// string txt = "空白!";
-
// Font font = new Font("宋体", 20, FontStyle.Bold);
-
// //存储一组整数,共四个,表示一个矩形的位置和大小。Rectangle(int x, int y, int width, int height);
-
// //参数为:矩形左上角的 x 坐标。矩形左上角的 y 坐标。矩形的宽度。矩形的高度。
-
// Rectangle r = new Rectangle(e.Bounds.Top+200, e.Bounds.Left+200,e.Bounds.Right, e.Bounds.Height);
-
// e.Graphics.DrawString(txt, font, Brushes.Purple, r);
-
//}
-
}
2、CellMerge(单元格合并):提供自定义单元合并行为的功能。需先设置gridView1.OptionsView.AllowCellMerge = true;
-
private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
-
{
-
if (e.Column.FieldName != "Name")
-
e.Handled = true; //获取或设置是否处理单元格合并操作,因此不需要进行默认处理。
-
}
3、CustomColumnDisplayText(自定义列显示):为数据单元格内的值、组行和过滤下拉菜单自定义显示文本
gridControl的每一列原始数据是Value,但是显示数据是DisplayText,默认DisplayText的值即是Value通过DisplayFormat转换后的值。
-
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
-
{
-
if (e.Column.FieldName == "Data")
-
{
-
string a = Convert.ToInt16(e.Value) < 0 ? "负数" : "正数"; //是否为正数
-
switch(a)
-
{
-
case "负数":
-
e.DisplayText = "负数据";
-
break;
-
case"正数":
-
e.DisplayText = "正数据";
-
break;
-
}
-
}
-
}
4、CustomDrawGroupRow(自定义绘制组行):允许手动绘制组行
-
private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
-
{
-
GridGroupRowInfo gridGroupRowInfo = e.Info as GridGroupRowInfo;
-
gridGroupRowInfo.GroupText = "第" + (e.RowHandle) + "行" + gridGroupRowInfo.EditValue;
-
}
5、CustomDrawRowIndicator(自定义行号显示):能够自定义绘制行指示器面板中的元素。需先设置行指示面板宽度gridView1.IndicatorWidth = 70;
-
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
-
{
-
if (e.Info.IsRowIndicator)
-
{
-
e.Info.DisplayText = "Row" + e.RowHandle;
-
}
-
}
6、RowCellClick(单元格点击事件):如果数据是可编辑的,事件将不会触发
-
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
-
{
-
if (e.Button == MouseButtons.Left) //鼠标左键
-
{
-
//执行的方法
-
}
-
if (e.Clicks == 2) //双击
-
{ }
-
if (e.Delta > 0)//鼠标滚轮滚动方向
-
{ }
-
if (e.X > 0 & e.Y > 0)//鼠标的坐标
-
{ }
-
if (e.RowHandle > 0) //点击的行号
-
{ }
-
if (e.CellValue != null)//点击的单元格中的值
-
{ }
-
if (e.Column != null)//点击的单元格所属列的信息
-
{ }
-
}
7、RowClick(行点击事件):如果点击数据是可编辑的,事件将不会触发
-
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
-
{
-
if (e.Clicks == 2) //双击
-
{ }
-
}
8、CustomDrawCell(重绘列样式):自定义绘制数据单元格
-
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
-
{
-
if (e.Column.Caption == "数据")
-
{
-
GridCellInfo gridCellInfo = e.Cell as GridCellInfo;
-
if (gridCellInfo.IsDataCell && double.Parse(gridCellInfo.CellValue.ToString()) < 0)
-
{
-
e.Appearance.BackColor = Color.Yellow;
-
}
-
else { e.Appearance.BackColor = Color.Green; }
-
}
-
}
9、CalcPreviewText(自定义备注):自定义备注文本 需先设置gridView1.OptionsView.ShowPreview = true;
-
private void gridView1_CalcPreviewText(object sender, DevExpress.XtraGrid.Views.Grid.CalcPreviewTextEventArgs e)
-
{
-
DataRow dr = gridView1.GetDataRow(e.RowHandle);
-
e.PreviewText = dr["Name"] + ":" + dr["Sex"];
-
}
10、RowCellStyle(定制单元格外观):允许单个单元格的外观设置得以更改
-
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
-
{
-
//GridView View = sender as GridView;
-
if (e.Column.FieldName == "Age" || e.Column.FieldName == "Data")
-
{
-
//string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Category"]);
-
string category = gridView1.GetRowCellDisplayText(e.RowHandle, gridView1.Columns["Name"]);
-
if (category == "张三")
-
{
-
e.Appearance.BackColor = Color.DeepSkyBlue;
-
e.Appearance.BackColor2 = Color.LightCyan;
-
}
-
}
-
}
11、RowStyle(定制行外观):允许更改各行的外观设置
-
private void gridView1_RowStyle(object sender, RowStyleEventArgs e)
-
{
-
GridView View = sender as GridView;
-
if (e.RowHandle >= 0)
-
{
-
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["Name"]);
-
if (category == "张三")
-
{
-
e.Appearance.BackColor = Color.DeepSkyBlue;
-
e.Appearance.BackColor2 = Color.SeaShell;
-
}
-
}
-
}
12、MasterRowGetRelationCount(主行获取关系数目):接管此事件来为每个主控行指定主/从关系的数目
-
private void gridView1_MasterRowGetRelationCount(object sender, MasterRowGetRelationCountEventArgs e)
-
{
-
e.RelationCount = 1; //显示1个关系,若设置为非正数则展开按钮被隐藏
-
}
13、MasterRowEmpty(指定当前细节视图是否有数据):允许指定细节是否为空
-
private void gridView1_MasterRowEmpty(object sender, MasterRowEmptyEventArgs e)
-
{
-
int a = e.RowHandle;//获取主控行的 句柄 由事件的 RowHandle 参数标识
-
int b = e.RelationIndex; //获取引用当前细节数据的 RelationIndex 参数
-
e.IsEmpty = false; //展示数据
-
}
14、MasterRowGetChildList(接管此事件来为当前细节视图提供数据):允许手动加载细节数据
-
private void gridView1_MasterRowGetChildList(object sender, MasterRowGetChildListEventArgs e)
-
{
-
//
-
}
15、MasterRowGetRelationName(接管此事件为当前关系 (细节) 提供名称):允许使用指定的细节视图 。需先构建GridControl.LevelTree 树
-
private void gridView1_MasterRowGetRelationName(object sender, MasterRowGetRelationNameEventArgs e)
-
{
-
e.RelationName = "关系";
-
}
16、MasterRowGetLevelDefaultView():允许使用指定细节模式视图
接管此事件来为当前呈现的细节视图显式提供模式视图。 通常,如果所需的模式视图不属于 GridControl.LevelTree 树,则需要接管此事件。 否则,在大多数情况下,可以通过 GridView.MasterRowGetRelationName 事件间接提供模式视图。
-
private void gridView1_MasterRowGetLevelDefaultView(object sender, MasterRowGetLevelDefaultViewEventArgs e)
-
{
-
//
-
}
一般属性设置 不显示分组框: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...
1497
通常我们在写主题程序或者新闻的程序中..字符太多了需要处理。使用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) ...
3623
原始数据格式:下面要求把“数据”设置为保留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页、历史记录搜索;