我正在使用“DevExpress”网格,当我将光标悬停在每个单元格上时,我想为每个单元格显示一个工具提示。我已经为此编写了代码。它工作正常并显示工具提示。但是当我在同一行上移动光标时,工具提示没有改变。 (水平移动)。但是,如果我离开当前行并返回,则工具提示会发生变化。请多多指教。
这是“toolTipController”的代码(我复制了整个方法以便更好地理解)
private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
bool validColumn = false;
if (e.SelectedControl != gridControl1)
return;
GridHitInfo hitInfo = gridView1.CalcHitInfo(e.ControlMousePosition);
if (hitInfo.InRow == false)
return;
if (hitInfo.Column == null)
return;
//concern only the following fields
if (hitInfo.Column.FieldName == "Monday" || hitInfo.Column.FieldName == "Tuesday" || hitInfo.Column.FieldName == "Wednesday" || hitInfo.Column.FieldName == "Thursday" || hitInfo.Column.FieldName == "Friday")
validColumn = true;
if (!validColumn)
return;
string toolTip = string.Empty;
SuperToolTipSetupArgs toolTipArgs = new SuperToolTipSetupArgs();
toolTipArgs.Title.Text = string.Empty;
//Get the data from this row
string columnCaption = hitInfo.Column.Caption;
DateTime dateOK = new DateTime(2000,1,1);
if (DateTime.TryParse(columnCaption, out dateOK))
{
DateTime date = DateTime.Parse(columnCaption);
int row = hitInfo.RowHandle;
long teacherID = long.Parse(gridView1.GetRowCellValue(row, "TeacherID").ToString());
GuaranteedDay gDay = db.GuaranteedDays.Where(p => p.Date == date && p.TeacherID == teacherID && p.Type == 5).FirstOrDefault();
if (gDay != null)
{
if (gDay.Note != string.Empty)
{
//Set description for the tool-tip
string description = string.Empty;
int type = gDay.Type;
switch (type)
{
case 1:
description = "guarantee offered";
break;
case 2:
description = "guaranteed";
break;
case 3:
description = "texted";
break;
case 4:
description = "available";
break;
case 5:
description = "unavailable";
break;
}
//Add Notes & description for the tool-tip
toolTip = "Notes : " + gDay.Note + "\nDescription : " + description;
string BodyText = toolTip;
toolTipArgs.Contents.Text = BodyText;
e.Info = new ToolTipControlInfo();
e.Info.Object = hitInfo.HitTest.ToString() + hitInfo.RowHandle.ToString();
e.Info.ToolTipType = ToolTipType.SuperTip;
e.Info.SuperTip = new SuperToolTip();
e.Info.SuperTip.Setup(toolTipArgs);
}
}
}
}
}
感谢您的帮助, 库山兰迪玛。
最佳答案
But the tool tip is not changing while I'm moving the cursor on the same row. (Moving Horizontally). But if I leave the current row and come back, then the tool tip changes.
我看到您已经为当前行中的任何单元格传递了相同的“hit-object”:
e.Info.Object = hitInfo.HitTest.ToString() + hitInfo.RowHandle.ToString();
要完成您的任务,您应该为不同的单元格传递不同的“hit-objects”:
e.Info.Object = hitInfo.HitTest.ToString() + hitInfo.RowHandle.ToString() + hitInfo.Column.FieldName;
关于c# - 显示 DevExpress 网格单元的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26342273/