显示DevExpress网格单元的工具提示

本文关键字:工具提示 单元 网格 DevExpress 显示 | 更新日期: 2023-09-27 18:26:19

我使用的是"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);
                }
            }
        }
    }
}

感谢您的帮助,Kushan Randima。

显示DevExpress网格单元的工具提示

但是当我在同一行上移动光标时,工具提示没有改变。(水平移动)。但是,如果我离开当前行并返回,则工具提示会发生变化。

我看到你已经为当前行中的任何单元格传递了相同的"命中对象":

e.Info.Object = hitInfo.HitTest.ToString() + hitInfo.RowHandle.ToString();  

为了完成任务,你应该为不同的单元格传递不同的"命中对象":

e.Info.Object = hitInfo.HitTest.ToString() + hitInfo.RowHandle.ToString() + hitInfo.Column.FieldName;