GridView.CustomDrawCell Event事件的应用
来源:互联网 发布:安卓手机安装linux 编辑:程序博客网 时间:2024/05/21 10:54
The event handler receives an argument of type RowCellCustomDrawEventArgs containing data related to this event.
The following RowCellCustomDrawEventArgs properties provide information specific to this event.Property
Description
Appearance
Gets the painted element's appearance settings.
Bounds
Returns a value specifying limits for the drawing area.
Cache
Gets an object which specifies the storage for the most often used pens, fonts and brushes.
Cell
Provides information on the painted cell.
CellValue
Gets the painted cell's value.
Column
Gets the column whose element is being painted.
DisplayText
Gets or sets the painted element's display text.
Graphics
Gets an object used to paint.
Handled
Gets or sets a value specifying whether an event was handled and that the default actions are therefore not required.
RowHandle
Gets the handle of a painted element's row.
事件包含的参数主要是上面列表展示的数据,在实际的开发中我们需要用到的主要参数也就是这几个,使用的流程是这样的,
1.判断列名称用到Column属性
2.判断单元格的值用到CellValue属性
3.根据单元格的值,设置我们想要的效果,若设这DisplayText,设置Appearence
4.e.Handled设置为true(大部分情况)
The CustomDrawCell event is raised before a data cell is painted. The cell that is going to be painted is identified by theRowCellCustomDrawEventArgs.RowHandle and RowCellCustomDrawEventArgs.Column parameters.
There are two scenarios for using the CustomDrawCell event:
- To paint data cells manually. The CustomDrawEventArgs.Handled parameter must be set to true. This indicates that you have handled the current call to the CustomDrawCell event and no default painting is required. With this approach, you need to paint cells in their entirety.
- Change a cell's settings and let the default painting mechanism paint the cell based on the provided settings. TheCustomDrawEventArgs.Handled parameter must be remain set to false. If the Handled parameter is set to false, the default painting mechanism is invoked for cells after your CustomDrawCell event handler is completed.
This approach is useful when you need to change the styles of cells (the CustomDrawEventArgs.Appearance parameter), their display texts (the RowCellCustomDrawEventArgs.DisplayText parameter), etc.
Note In some cases, a cell's background may not be repainted by the default painting mechanism after your CustomDrawCell event handler is completed, even if the Handled parameter is set to false. For instance, if you draw a line, this line may be visible even if you set theHandled parameter to false. The cell's default text may be painted over your custom line. However, this is not always true. For instance, if you handle the RowCellStyle event (in addition to the CustomDrawCell event) and customize the cell's background color(s), custom drawing will be cleared and the cell's background will be repainted by the default painting mechanism after your CustomDrawCell event handler is completed.
We do not recommend that you rely on this behavior, as it may change in future.
注意事项:
1.事件发生在数据被绘制在单元格之前(此时行已经有了数据,单元格也有了数据只是还没有paint出来),所以如果你自己给单元格的值(自己paint),必须将e.Handled设置为true;
The following code demonstrates how to use the CustomDrawCell event to set up the appearance of "UnitsInStock" column cells. If a cell belongs to the focused row, custom draw is not applied and the cell is drawn by default. Otherwise the background of a cell is drawn according to its value.
Also we do not perform custom painting of a cell if the "Discontinued" column cell of the same row is checked. Instead, we just change the DisplayText parameter to "Discontinued" and leave the Handled parameter set to false. This text will be drawn using the default appearance settings after performing the event handler.
If a value of the "Discontinued" column is set to false, the background of the "UnitsInStock" cell of the same row is drawn using the LightSkyBlue or "LightGreen" color according to the cell value. In ths case, the Handled parameter is set to true in order to prevent default cell painting.
using DevExpress.XtraGrid.Views.Grid;using DevExpress.XtraGrid.Views.Base;private void advBandedGridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) { GridView currentView = sender as GridView; if(e.RowHandle == currentView.FocusedRowHandle) return; Rectangle r = e.Bounds; if(e.Column.FieldName == "UnitsInStock") { bool check = (bool)currentView.GetRowCellValue(e.RowHandle, currentView.Columns["Discontinued"]); if(check) { //Change the text to display //The e.Handled parameter is false //So the cell will be painted using the default appearance settings e.DisplayText = "Discontinued"; } else { // If the cell value is greater then 50 the paint color is LightGreen, // otherwise LightSkyBlue Brush ellipseBrush = Brushes.LightSkyBlue; if (Convert.ToInt16(e.CellValue) > 50) ellipseBrush = Brushes.LightGreen; //Draw an ellipse within the cell e.Graphics.FillEllipse(ellipseBrush, r); r.Width -= 12; //Draw the cell value e.Appearance.DrawString(e.Cache, e.DisplayText, r); //Set e.Handled to true to prevent default painting e.Handled = true; } }}
- GridView.CustomDrawCell Event事件的应用
- 点击事件的event的应用
- Event事件处理机制的实例应用
- GridView事件应用
- Flex4自定义事件类型Event的相关应用
- 【C#】Event事件的应用之观察者模式
- 【C#】Event事件的应用之观察者模式
- [转]Raising An Event From CheckBox In A GridView (GridView中模板表的CheckBox的后台事件处理)
- jq的event事件
- javascript的事件(event)
- SWT的Event(事件)
- msyql的事件event
- Event事件的兼容性
- 常见的event事件
- GridView行编辑事件及新增行事件的应用
- .Net: delegate(委托)、event(事件) 应用
- python中event事件应用举例
- GridView的事件说明
- 读取配置文件
- Red hat 5.4 安装Eclipse 出现的问题
- 利用华为短信包开发短信功能中中文转码和msgId获取经验
- 正式的和临时的中国人
- 申请Android Map API Key
- GridView.CustomDrawCell Event事件的应用
- C语言求解约瑟夫问题
- JS 添加千分位 与 去掉千分位
- Android.mk文件编写以及import-module的注意事项与NDK_MODULE_PATH的配置
- JS 的加载执行顺序 .
- Mac OS X 10.8.X编译Android4.2.X源码不生成emulator的问题
- mybatis中调用oracle自定义函数
- 几个ARM指令操作的汇编实现
- hdu1060-Leftmost Digit