Kushan Randima
Kushan Randima

Reputation: 2300

Show tool-tips for DevExpress grid cells

I am using a "DevExpress" grid and I would like to display a tool-tip for each cell as I hover the cursor over it. I have written a code for that. It works fine and show tool-tips. 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. Please advise me.

Here is the code for "toolTipController" (I have copied the whole method for a better understanding)

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);
                }
            }
        }
    }
}

Thanks for helping, Kushan Randima.

Upvotes: 4

Views: 5786

Answers (1)

DmitryG
DmitryG

Reputation: 17848

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.

I see that you've passed the same "hit-object" for any cells within the current row:

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

To accomplish your task, you should pass the different "hit-objects" for different cells:

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

Upvotes: 5

Related Questions