This is a migrated thread and some comments may be shown as answers.

Problems how to set tooltip and use currentcell

5 Answers 407 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Henning
Top achievements
Rank 1
Henning asked on 14 Jan 2013, 07:38 AM
Hi,

I'm working on an application in WinForms which uses a RadGridView to display information.
I have run "out of space" and want to display further information as tooltip.
When I databind the grid, I place this information in a column with Visible=false.

I have tried two ways withoug success.
First I tried he CellFormatting event as described in the Help Section on www.telerik.com.
private void gwOffer_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (gwOffer.Rows[e.CellElement.RowIndex].Cells["FieldA"].Value != null)
    {
        if (gwOffer.Rows[e.CellElement.RowIndex].Cells["FieldB"].Value != null)
        {
            e.CellElement.ToolTipText = "Sagsstatus: " + gwOffer.Rows[e.CellElement.RowIndex].Cells["FieldB"].Value;
        }
    }
}
I only want to display the tooltip, if there is information to show (FieldB is in the hidden column), but I get values everywhere, and the values are often wrong.

Then I tried to do it manually by using the DataBindingComplete and the CurrentCell property also described in the Help Section on www.telerik.com.
 
private void gwOffer_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    for (int i = 0; i < gwOffer.Rows.Count; i++)
    {
        if (gwOffer.Rows[i].Cells["FieldA"].Value != null)
        {
            if (gwOffer.Rows[i].Cells["FieldB"].Value != null)
            {
                gwOffer.CurrentRow = gwOffer.Rows[i];
                gwOffer.CurrentColumn = gwOffer.Columns["FieldA"];
                GridDataCellElement cell = gwOffer.CurrentCell;
                if(cell!=null)
                    cell.ToolTipText = "Sagsstatus: " + gwOffer.Rows[i].Cells["FieldB"].Value;
            }
        }
    }
}
My problem is that CurentCell is always null.

I hope you can help me how to do this.


Best regards
Henning

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 17 Jan 2013, 07:13 AM
Hello Henning,

Thank you for writing.

There are two ways to show tool tips:

1) You can set ToolTips to CellElements in the CellFormatting event handler. In the CellFormatting event handler the tooltip text is assigned to the ToolTip property for the given CellElement. The following example will assign a tooltip for the data cells in the FieldA column, if both the cells (FieldA and FieldB) on the same row has a value:
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement is GridDataCellElement &&
        e.Column.Name == "FieldA" &&
        e.Row.Cells["FieldA"].Value != null &&
        e.Row.Cells["FieldB"].Value != null)
    {
        e.CellElement.ToolTipText = "Sagsstatus: " + e.Row.Cells["FieldB"].Value;
    }
}

2) You can use ToolTipTextNeeded event for showing tool tips which serves for assigning tooltips to different elements. Here is a sample code implementation:
void radGridView1_ToolTipTextNeeded(object sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
{
    GridDataCellElement hoveredCell = sender as GridDataCellElement;
    if (hoveredCell != null && hoveredCell.ColumnInfo.Name == "FieldA")
    {
        e.ToolTipText = "Sagsstatus: " + hoveredCell.RowInfo.Cells["FieldB"].Value;
    }
}

Attached you can find a sample project where my suggestions were implemented.

If you have any additional questions, do not hesitate to ask.

Kind regards,
Plamen
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Henning
Top achievements
Rank 1
answered on 25 Jan 2013, 02:53 PM
Hi Plamen,

Sorry for the late answer, and thank you for the sample.
I'll give it a go.


BR
Henning
0
Henning
Top achievements
Rank 1
answered on 28 Jan 2013, 07:21 AM
Hi Plamen,

I have tried the CellFormatting event, at it works really well.
Now, my Project Manager has come up with the idea to set the cell back color instead, using say red, green, yellow according to the conditions.
I have written the example below, which works almost as expected.
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
  
{
  
    if (e.CellElement is GridDataCellElement &&
  
        e.Column.Name == "FieldA" &&
 
        e.Row.Cells["FieldA"].Value != null &&
 
        e.Row.Cells["FieldB"].Value != null)
  
    {
  
       e.CellElement.BackColor = Color.Green;
  
    }
  
}

The changed cell back color is only wisible, when I hover og click the row. I'd like it to be permanently visible. Should I use another property instead?


BR
Henning
0
Accepted
Plamen
Telerik team
answered on 30 Jan 2013, 02:44 PM
Hello Henning,

Thank you for writing.

The observed behavior on your end is caused by the fact that DrawFill property is set to false by default. Please conisder the following code in the CellFormatting:
if (YourCondition)
{
    e.CellElement.DrawFill = true;
    e.CellElement.GradientStyle = GradientStyles.Solid;
    e.CellElement.BackColor = Color.Red;
}
else
{
    e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
    e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
    e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}

Due to the UI virtualization in RadGridView, cell elements are created only for the currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse) all customizations should be reset for the rest of the cell elements. In addition, you could read the following documentation articles:

I hope that you find my information useful. Feel free to write back, If you have any problems or questions related to this topic.

Regards,
Plamen
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Henning
Top achievements
Rank 1
answered on 30 Jan 2013, 03:29 PM
Hi Plamen,

I have implemented the suggested changes, and it works as expected.
Thank you for helping me.


BR
Henning
Tags
GridView
Asked by
Henning
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Henning
Top achievements
Rank 1
Share this question
or