使用DevExpress GridControl控件时经常用的方法
//扩展
public static class tool
{
<span style="white-space:pre"> </span>/// <summary>
/// 设置行头显示行数据信息
/// </summary>
public static DevExpress.XtraGrid.GridControl ExecuteSetRowHandShowInfo(this DevExpress.XtraGrid.GridControl _GridControl)
{
DevExpress.XtraGrid.Views.Grid.GridView _GridView=(DevExpress.XtraGrid.Views.Grid.GridView)_GridControl.MainView;
System.ComponentModel.IContainer components = new System.ComponentModel.Container();
DevExpress.Utils.ToolTipController toolTipControlInfo2 = new DevExpress.Utils.ToolTipController(components);
toolTipControlInfo2.GetActiveObjectInfo += new DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventHandler(delegate(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
try
{
ToolTipControlInfo toolTipControlInfo = null;
if (_GridView == null)
return;
var gridHitInfo = _GridView.CalcHitInfo(e.ControlMousePosition);
if (gridHitInfo.HitTest == GridHitTest.RowIndicator)
{
if (int.Parse(gridHitInfo.RowHandle.ToString()) < 0)
{
return;
}
object obj = gridHitInfo.HitTest + gridHitInfo.RowHandle.ToString();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("基本信息:\r\n");
foreach (GridColumn gridColumnInfo in _GridView.Columns)
{
if (gridColumnInfo.Visible)
{
stringBuilder.AppendFormat(" {0}:{1}\r\n",
gridColumnInfo.Caption.Equals("") ? gridColumnInfo.FieldName : gridColumnInfo.Caption,
_GridView.GetRowCellDisplayText(gridHitInfo.RowHandle, gridColumnInfo.FieldName));
}
}
toolTipControlInfo = new ToolTipControlInfo(obj, stringBuilder.ToString());
}
if (toolTipControlInfo != null)
{
e.Info = toolTipControlInfo;
}
}
catch (Exception ex)
{
}
});
_GridControl.ToolTipController = toolTipControlInfo2;
return _GridControl;
}
}
this.NotChineseDrugControl.ExecuteSetRowHandShowInfo();