【问题标题】:Show tool-tips for DevExpress grid cells显示 DevExpress 网格单元的工具提示
【发布时间】:2014-12-08 03:40:00
【问题描述】:

我正在使用“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);
                }
            }
        }
    }
}

感谢您的帮助, 贵霜兰迪玛。

【问题讨论】:

    标签: c# winforms gridview devexpress tooltip


    【解决方案1】:

    但是当我将光标移动到同一行时,工具提示没有改变。 (水平移动)。 但是如果我离开当前行并返回,那么工具提示就会改变。

    我看到您为当前行中的任何单元格传递了相同的“命中对象”:

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

    要完成您的任务,您应该为不同的单元传递不同的“命中对象”:

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

    【讨论】:

    • 您描述的阻止是在automatically 执行的,以保持 SO 站点的高质量。这是一个很好的规则。以后请遵循How do I ask a good questionhelp-article 的建议。快乐堆栈溢出!)关于这个具体问题 - 我觉得很好。
    • 感谢您对我的询问的回复。感谢您提供给我的信息
    猜你喜欢
    • 2018-10-25
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多