1.添加 DevExpress.Utils.ToolTipController 提示文本控件
2.设置表格属性 myGridControl.ToolTipController = this.toolTipController1;
3.编写事件GetActiveObjectInfo方法,设置提示信息。
private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
if (e.SelectedControl != gcMachine) return;
ToolTipControlInfo info = null;
try
{
GridView view = gcMachine.GetViewAt(e.ControlMousePosition) as GridView;
if (view == null) return;
GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
if (hi.InRowCell)
{
info = new ToolTipControlInfo(new CellToolTipInfo(hi.RowHandle, hi.Column, "cell"), GetCellHintText(view, hi.RowHandle, hi.Column));
return;
}
}
finally
{
e.Info = info;
}
}
private string GetCellHintText(GridView view, int rowHandle, DevExpress.XtraGrid.Columns.GridColumn column)
{
if (column.FieldName != SELECT_FIELD_NAME)
{
string cellVal = view.GetRowCellValue(rowHandle, column).ToString();
//foreach (DevExpress.XtraGrid.Columns.GridColumn col in view.Columns)
// if (col.VisibleIndex < 0)
// ret += string.Format("\r\n {0}: {1}", col.GetTextCaption(), view.GetRowCellDisplayText(rowHandle, col));
if (string.IsNullOrEmpty(cellVal) == false)
{
TipStringBuilder.Clear();
//ToolTipDisplay.Remove(0, ToolTipDisplay.Length);
if (IsMachineRow(rowHandle) == true)
{//机器
CellMachine model = LstCellMachine.FirstOrDefault(m => m.ID == Convert.ToInt32(cellVal));//机器ID
if (model != null)
{
bool hasConflict = false;
if (SelectMachineFromType == SelectMachineTypes.ProductionSelect)
{//显示生产单号
MachineStates machineState = model.GetMachineState();
if (machineState == MachineStates.Conflict)
{
if (DicMachinePlans.ContainsKey(model.ID))
{
hasConflict = true;
List<VirtualProduction> lstVirtualProdEvent = DicMachinePlans[model.ID] as List<VirtualProduction>;
bool isFirst = true;
foreach (VirtualProduction vpe in lstVirtualProdEvent)
{
string startTime = string.Format("{0} {1}", vpe.StartTime.ToStringEx(), vpe.StartTime.ToLongTimeString());
string endTime = string.Format("{0} {1}", vpe.EndTime.ToStringEx(), vpe.EndTime.ToLongTimeString());
if (isFirst == true)
{
TipStringBuilder.AppendFormat("{0}\t{1}\t{2}", vpe.PoCodes, startTime, endTime);
isFirst = false;
}
else
{
TipStringBuilder.AppendFormat("\r\n{0}\t{1}\t{2}", vpe.PoCodes, startTime, endTime);
}
}
}
}
}
#if DEBUG
if (hasConflict == true)
TipStringBuilder.AppendFormat("\r\n{0}: {1}", "ID", model.ID);
else
TipStringBuilder.AppendFormat("\r{0}: {1}", "ID", model.ID);
#endif
TipStringBuilder.AppendFormat("\r\n {0}: {1}", CText.GetCommonMsgText("Brand", "品牌"), model.Brand);//品牌
TipStringBuilder.AppendFormat("\r\n {0}: {1}", CText.GetCommonMsgText("XingHao", "型号"), model.MachineModel);//型号
TipStringBuilder.AppendFormat("\r\n {0}: {1}", CText.TextDescription, model.Description);//备注
}
}
else
{//机种
MachineType mt = LstMachineType.Find(m => m.Name == cellVal);//机种名称
if (mt != null)
{
TipStringBuilder.AppendFormat("{0}: {1}", CText.TextDescription, mt.Description);//备注
}
}
}
return TipStringBuilder.ToString();
}
else
{
return string.Empty;
}
}