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

How to embed a GridView in a ScreenTip?

16 Answers 244 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 14 Nov 2012, 08:02 AM
Hi Guys

I'm trying to embed a gridview in a screen tip in order to display information about a cell in an underlying grid when that cell IsMouseOver.

I'm using the following code embedding a grid in a RadHostItem and then adding that to the Items collection of the screentip. Debugging shows that the RadHostItem and its grid are appearing in the collection but the Grid does not display when the screentip is displayed.
Any help to solve this would be appreciated.

Many thanks in advance
Regard
Ian Carson

void rgvOperationsGrid_ScreenTipNeeded(object sender, ScreenTipNeededEventArgs e)
{
    var cell = e.Item as GridDataCellElement;
 
    if (cell == null ) return;
    if(cell.ColumnIndex==5 || cell.ColumnIndex==7)
        ShowParameterScreenTipForCell(cell);
 
}
 
private void ShowParameterScreenTipForCell(GridDataCellElement cell)
{
    var tipGrid = new RadGridView();
    tipGrid.Columns.Add(new GridViewTextBoxColumn {HeaderText = "This is a column"});
    tipGrid.MasterTemplate.BestFitColumns();
    var rowInfo = tipGrid.Rows.AddNew();
    rowInfo.Cells[0].Value = "Hello";
 
    var screenTip = new RadOffice2007ScreenTipElement();
    screenTip.ThemeRole = "Office2010Silver";
    screenTip.AutoSize = false;
    screenTip.Size = new Size(200, 200);
    screenTip.CaptionLabel.Text = "This is a Screen Tip";
    var contentItem = new RadHostItem(tipGrid);
    contentItem.MinSize = new Size(100, 100);
 
    //contentItem.Image = Resources.Execution24;
    //contentItem.FitToSizeMode = RadFitToSizeMode.FitToParentBounds;
 
    screenTip.Items.Insert(1, contentItem);
    cell.ScreenTip = screenTip;
}

16 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Nov 2012, 10:31 AM
Hello Ian,

As far as i know there is no "clean" way of doing this, but if you are willing to use some reflection for this, you can change your method like this:
private void ShowParameterScreenTipForCell(GridDataCellElement cell)
       {
           var tipGrid = new RadGridView();
           tipGrid.Dock = DockStyle.Fill;
           tipGrid.MinimumSize = new Size(100, 100);
           tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "This is a column" });
           tipGrid.MasterTemplate.BestFitColumns();
           var rowInfo = tipGrid.Rows.AddNew();
           rowInfo.Cells[0].Value = "Hello";
 
           var screenTip = new RadOffice2007ScreenTipElement();
           screenTip.ThemeRole = "Office2010Silver";
           screenTip.AutoSize = false;
           screenTip.Size = new Size(200, 200);
           screenTip.CaptionLabel.Text = "This is a Screen Tip";
           var contentItem = new RadHostItem(tipGrid);
           contentItem.MinSize = new Size(100, 100);
           var fieldInfo = screenTip.GetType().GetField("screenTipPanel", BindingFlags.NonPublic | BindingFlags.Instance);
           if (fieldInfo != null)
           {
               var field = fieldInfo.GetValue(screenTip) as StackLayoutPanel;
               if (field != null)
               {
                   field.Children.Add(contentItem);
               }
           }
 
           cell.ScreenTip = screenTip;
       }

If you have any other questions, please let me know.

Best Regards,
Emanuel Varga
WinForms MVP
0
Ian
Top achievements
Rank 1
answered on 14 Nov 2012, 01:13 PM
HI Emanuel,
Your reflection tip worked well but it inevitably leads me to the question of fitting a variable sized grid into a properly sized screentip.

I have been trying to make the screentip dynamically sized to fit whatever grid content is produced but so far with little success. I suspect another "something under the covers" will be the solution. :-)

Any help yu can give would be appreciated a salways
Regards
Ian

Here's the code I'm trying

private void ShowParameterScreenTipForCell(GridDataCellElement cell)
{
    var function = (FunctionType) cell.RowInfo.Cells[cell.ColumnIndex].Tag;
    var parameters = function.Parameters;
 
    var tipGrid = new RadGridView
                      {
                          ThemeName = "Office2010Silver",
                          AllowAddNewRow = false,
                          AllowColumnChooser = false,
                          AllowColumnHeaderContextMenu = false,
                          AllowColumnReorder = false,
                          AllowDeleteRow = false,
                          AllowDragToGroup = false,
                          AllowEditRow = false,
                          AllowRowReorder = false,
                          AllowRowResize = false,
                          EnableGrouping = false,
                          EnableHotTracking = false,
                          EnableSorting = false,
                          ShowGroupPanel = false,
                          ShowRowHeaderColumn = false
                      };
 
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Name"});
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Upper Value" });
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Lower Value" });
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "List Value" });
 
    tipGrid.MasterTemplate.BestFitColumns();
 
    foreach (var para in parameters)
    {
        var rowInfo = tipGrid.Rows.AddNew();
        rowInfo.Cells[0].Value = para.Name;
    }
 
    foreach (var col in tipGrid.Columns)
    {
        col.AutoSizeMode = BestFitColumnMode.DisplayedCells;
    }
 
    var gridSize = tipGrid.Size;
 
    var screenTip = new RadOffice2007ScreenTipElement{AutoSize=false};
    screenTip.CaptionLabel.Text = function.Name;
    var contentItem = new RadHostItem(tipGrid){AutoSize=false, Size=gridSize};
 
    var fieldInfo = screenTip.GetType().GetField("screenTipPanel", BindingFlags.NonPublic | BindingFlags.Instance);
 
    if (fieldInfo != null)
    {
        var field = fieldInfo.GetValue(screenTip) as StackLayoutPanel;
 
        if (field != null)
        {
            field.Children.Add(contentItem);
        }
    }
 
    cell.ScreenTip = screenTip;
}

0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Nov 2012, 02:30 PM
Hello again,

There are a couple of problems here, i'm bringing this up because you mentioned a variable sized grid, because it is a screentip the user will not be able to interact with that grid, are you sure you want this behavior?
If by varied you mean not to big grid you could do a few things:
1) Take a specific size and stick to it (x / y) and you can assign this by using
screenTip.EnableCustomSize = true;
screenTip.TipSize = new Size(500,300);
but from what i saw in my tests, for any reason (i don't know why), you have to have the autosize set to true on the screentip for this to work
var screenTip = new RadOffice2007ScreenTipElement { AutoSize = true };

2) You could take a specific width for the grid and calculate the height based on the number of rows
foreach (var para in parameters)
{
    var rowInfo = tipGrid.Rows.AddNew();
    rowInfo.Cells[0].Value = para.Name;
}
tipGrid.ClearSelection();
tipGrid.CurrentRow = null;
 
tipGrid.MinimumSize = new Size(tipGrid.Width, 20+(tipGrid.RowCount*24));
 
foreach (var col in tipGrid.Columns)
{
    col.AutoSizeMode = BestFitColumnMode.DisplayedCells;
}
 
var gridSize = tipGrid.Size;
 
var screenTip = new RadOffice2007ScreenTipElement { AutoSize = true };
 
screenTip.CaptionLabel.Text = function.Name;
var contentItem = new RadHostItem(tipGrid) { AutoSize = false, Size = gridSize };
 
var fieldInfo = screenTip.GetType().GetField("screenTipPanel", BindingFlags.NonPublic | BindingFlags.Instance);
 
if (fieldInfo != null)
{
    var field = fieldInfo.GetValue(screenTip) as StackLayoutPanel;
 
    if (field != null)
    {
        field.Children.Add(contentItem);
    }
}
screenTip.EnableCustomSize = true;
screenTip.TipSize = new Size(500, gridSize.Height+18);
cell.ScreenTip = screenTip;

or 3) take the width into consideration, but this requires some extra calculations to be done...

Please let me know if there is anything else i can do to help.

Best Regards,
Emanuel Varga
WinForms MVP
0
Ian
Top achievements
Rank 1
answered on 14 Nov 2012, 11:51 PM
Hi Emanuel

I'd really like to take width into account as well and was wondering what calculations are needed to get the correct width. I have tried for a couple of hours this morning but although I thought I had it with "RowWidth", that property has been deprecated and the new RowLayout.DesiredSize is not being set.

Thanks again for your help
Regards
Ian
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Nov 2012, 08:32 AM
Hello Ian,

Please take a look at this thread.
Here i did some work on how to actually resize the columns upon calculating the size of the text displayed inside the column, if you were to use that one, and set the minimum and maximum width of the column, then you should be able to use those to set the size of the tooltip.

If you need more help on this i will try to provide a fully working sample.

Best Regards,
Emanuel Varga
WinForms MVP

0
Ian
Top achievements
Rank 1
answered on 16 Nov 2012, 04:10 AM
Hi Emanuel

I have had a go at getting the width and height correct for the screen tip using your suggested thread (see the code below) it's very close but it's still not quite right.

There seem to be elements of the grid (perhaps padding and margin values?) which I have compensated for with the addition of integer values to the width and height at various points in the calculation but for which there should be some way to know those values and add them correctly.

What I would like to see is a screen tip with an embedded grid without extra white space around it. If you were able to help me with this that would be fantastic.

Regards
Ian

private void ShowParameterScreenTipForCell(GridDataCellElement cell)
{
    var function = (FunctionType) cell.RowInfo.Cells[cell.ColumnIndex].Tag;
    var parameters = function.Parameters;
 
    if (function.FunctionExecID == 10000) return;
    if (!parameters.Any()) return;
 
    var tipGrid = new RadGridView
                      {
                          ThemeName = "Office2010Silver",
                          AllowAddNewRow = false,
                          AllowColumnChooser = false,
                          AllowColumnHeaderContextMenu = false,
                          AllowColumnReorder = false,
                          AllowDeleteRow = false,
                          AllowDragToGroup = false,
                          AllowEditRow = false,
                          AllowRowReorder = false,
                          AllowRowResize = false,
                          EnableGrouping = false,
                          EnableHotTracking = false,
                          EnableSorting = false,
                          ShowGroupPanel = false,
                          ShowRowHeaderColumn = false,
                          AutoScroll = false,
                          Dock = DockStyle.Fill
                      };
 
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Name"});
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Upper Value" });
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Lower Value" });
    tipGrid.Columns.Add(new GridViewTextBoxColumn { HeaderText = "List Value" });
 
    tipGrid.MasterTemplate.BestFitColumns();
 
    foreach (var para in parameters)
    {
        var rowInfo = tipGrid.Rows.AddNew();
        rowInfo.Cells[0].Value = para.Name;
    }
 
    tipGrid.ClearSelection();
    tipGrid.CurrentRow = null;
    var gridWidth = CalculateGridWidth(tipGrid);
 
    tipGrid.MinimumSize = new Size(gridWidth, 36 + (tipGrid.RowCount * 24));
 
    foreach (var col in tipGrid.Columns)
    {
        col.AutoSizeMode = BestFitColumnMode.DisplayedCells;
    }
 
    var gridSize = tipGrid.MinimumSize;
    var width = 0;
 
    var screenTip = new RadOffice2007ScreenTipElement{AutoSize=true};
    screenTip.CaptionLabel.Text = function.Name;
    screenTip.MainTextLabel.Text = "Parameters";
    var contentItem = new RadHostItem(tipGrid)
                          {
                              AutoSize = true,
                              MinSize = new Size(gridWidth + 12, gridSize.Height + 12),
                              AutoSizeMode = RadAutoSizeMode.WrapAroundChildren
                          };
 
    var fieldInfo = screenTip.GetType().GetField("screenTipPanel", BindingFlags.NonPublic | BindingFlags.Instance);
 
    if (fieldInfo != null)
    {
        var field = fieldInfo.GetValue(screenTip) as StackLayoutPanel;
 
        if (field != null)
        {
            field.Children.Add(contentItem);
        }
    }
    screenTip.EnableCustomSize = true;
    screenTip.TipSize = new Size(contentItem.MinSize.Width + 6, contentItem.MinSize.Height);
    screenTip.UpdateLayout();
    cell.ScreenTip = screenTip;
}
 
private int CalculateGridWidth(RadGridView tipGrid)
{
    var minWidth=0;
 
    foreach (var row in tipGrid.Rows)
    {
        var rowWidth = 0;
 
        for (var i = 0; i < row.Cells.Count; i++)
        {
            var headerWidth = (int)rgvOperationsGrid.CreateGraphics().MeasureString(row.Cells[i].ColumnInfo.HeaderText, rgvOperationsGrid.Font).Width + 6;
 
            if (row.Cells[i].Value != null)
            {
                var cellWidth =(int)rgvOperationsGrid.CreateGraphics().MeasureString(row.Cells[i].Value.ToString(), rgvOperationsGrid.Font).Width;
                cellWidth += 6;
 
                if (cellWidth > headerWidth)
                {
                    rowWidth += cellWidth;
                }
                else
                {
                    rowWidth += headerWidth;
                }
 
            }
            else
            {
                rowWidth += headerWidth;
            }
 
        }
        if (rowWidth > minWidth)
        {
            minWidth = rowWidth;
        }
    }
 
    return minWidth;
}

0
Jack
Telerik team
answered on 19 Nov 2012, 09:15 AM
Hello Ian,

You can do this in a more simple way. You can add RadGridViewElement directly to the screen tip element tree. Please consider the following sample:

void button_ScreenTipNeeded(object sender, ScreenTipNeededEventArgs e)
{
    RadOffice2007ScreenTipElement screenTip = new RadOffice2007ScreenTipElement();
    screenTip.ThemeRole = "Office2010Silver";
    screenTip.CaptionLabel.Text = "This is a Screen Tip";
    screenTip.MainTextLabel.Text = "";
 
    RadGridViewElement grid = new RadGridViewElement();
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column1"));
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column2"));
    grid.Template.Rows.Add("1", "first");
    grid.Template.Rows.Add("2", "second");
    grid.Template.Rows.Add("3", "third");
    screenTip.MainTextLabel.Children.Add(grid);
 
    RadButtonElement button = (RadButtonElement)e.Item;
    button.ScreenTip = screenTip;
}

In this scenario screen tip determines its size automatically based on its content and there is no need to use reflection.

If you have questions, do not hesitate to write back.
 
Regards,
Jack
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Nov 2012, 10:53 AM
Hello Jack,

I just tested this scenario and although it is calculating it's height properly, it is not calculating the width properly, please take a look at Ian's example, modified a bit:
private void grid_ScreenTipNeeded(object sender, Telerik.WinControls.ScreenTipNeededEventArgs e)
{
    var cell = e.Item as GridDataCellElement;
 
    if (cell == null) return;
 
    //if (cell.ColumnIndex == 5 || cell.ColumnIndex == 7)
    //ShowParameterScreenTipForCell(cell);
 
    RadOffice2007ScreenTipElement screenTip = new RadOffice2007ScreenTipElement();
    screenTip.ThemeRole = "Office2010Silver";
    screenTip.CaptionLabel.Text = "This is a Screen Tip";
    screenTip.MainTextLabel.Text = "";
    var function = new FunctionType() { Name = "Function X" };
    List<FunctionParam> parameters = new List<FunctionParam>();
    for (int i = 0; i < new Random().Next(10, 40); i++)
    {
        parameters.Add(new FunctionParam { Name = "Parameter + " + i });
    }
 
    RadGridViewElement grid = new RadGridViewElement();
    grid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Name" });
    grid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Upper Value" });
    grid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = "Lower Value" });
    grid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = "List Value" });
    foreach (var para in parameters)
    {
        var rowInfo = grid.Template.Rows.AddNew();
        rowInfo.Cells[0].Value = para.Name;
    }
    screenTip.MainTextLabel.Children.Add(grid);
 
     
    cell.ScreenTip = screenTip;
}

Best Regards,
Emanuel Varga
WinForms MVP
0
Ian
Top achievements
Rank 1
answered on 19 Nov 2012, 11:28 PM
Hi Emanuel and Jack

The Child Element approach looks good but I have also noticed the width issue. I have been trying with the GridWidth calculator method (see earlier posts) but an automatic version would be great.

I'm also struggling to find where I can set the Theme for the RadGridViewElement perhaps one of you can point me in the right direction on this as well.

The latest Grid show method I'm using is below

Regards
Ian

private void ShowParameterScreenTipForCell(GridDataCellElement cell)
{
    var function = (FunctionType) cell.RowInfo.Cells[cell.ColumnIndex].Tag;
    var parameters = function.Parameters;
 
    if (function.FunctionExecID == 10000) return;
    if (!parameters.Any()) return;
 
    var tipGrid = new RadGridViewElement
    {
        ShowGroupPanel = false,
    };
 
    tipGrid.Template.AllowAddNewRow = false;
    tipGrid.Template.AllowColumnChooser = false;
    tipGrid.Template.AllowColumnHeaderContextMenu = false;
    tipGrid.Template.AllowColumnReorder = false;
    tipGrid.Template.AllowDeleteRow = false;
    tipGrid.Template.AllowDragToGroup = false;
    tipGrid.Template.AllowEditRow = false;
    tipGrid.Template.AllowRowReorder = false;
    tipGrid.Template.AllowRowResize = false;
    tipGrid.Template.EnableGrouping = false;
    tipGrid.TableElement.EnableHotTracking = false;
    tipGrid.Template.EnableSorting = false;
    tipGrid.Template.ShowRowHeaderColumn = false;
 
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Name") });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Upper Value") });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Lower Value") });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "List Value") });
 
 
 
    foreach (var para in parameters)
    {
        var rowInfo = tipGrid.Template.Rows.AddNew();
         
        var valueList = para.ParameterValues.Where(a => a.default_).ToList();
        switch(para.ParameterValueType)
        {
            case Enumerations.ParameterType_ParameterValueType.Range:
                rowInfo.Cells[0].Value = para.Name;
                rowInfo.Cells[1].Value = valueList.First().Valuestring;
                rowInfo.Cells[2].Value = valueList.Last().Valuestring;
                rowInfo.Cells[3].Value = String.Empty;
                break;
            case Enumerations.ParameterType_ParameterValueType.Value:
                rowInfo.Cells[0].Value = para.Name;
                rowInfo.Cells[1].Value = valueList.First().Valuestring;
                rowInfo.Cells[2].Value = String.Empty;
                rowInfo.Cells[3].Value = String.Empty;
                break;
            case Enumerations.ParameterType_ParameterValueType.List:
                if(para.ParameterDataType == Enumerations.ParameterType_ParameterDataType.Identifier)
                {
                    rowInfo.Cells[0].Value = para.Name;
                    rowInfo.Cells[1].Value = String.Empty;
                    rowInfo.Cells[2].Value = String.Empty;
                    rowInfo.Cells[3].Value = "Identifier List";
                }
                else
                {
                    var i = 0;
                    foreach(var paraValue in valueList)
                    {
                        if(i==0)
                        {
                            rowInfo.Cells[0].Value = para.Name;
                            rowInfo.Cells[1].Value = String.Empty;
                            rowInfo.Cells[2].Value = String.Empty;
                            rowInfo.Cells[3].Value = paraValue.Valuestring;
                        }
                        else
                        {
                            var rowInfo2 = tipGrid.Template.Rows.AddNew();
                            rowInfo2.Cells[0].Value = String.Empty;
                            rowInfo2.Cells[1].Value = String.Empty;
                            rowInfo2.Cells[2].Value = String.Empty;
                            rowInfo2.Cells[3].Value = paraValue.Valuestring;
                        }
 
                        i++;
                    }
                }
 
                break;
        }
    }
 
    SetConditions(tipGrid);
 
    tipGrid.CurrentRow = null;
    var gridWidth = CalculateGridWidth(tipGrid);
 
    tipGrid.TableElement.MinSize = new Size(gridWidth, 36 + (tipGrid.Template.RowCount * 24));
 
    foreach (var col in tipGrid.Template.Columns)
    {
        col.AutoSizeMode = BestFitColumnMode.DisplayedCells;
    }
 
    tipGrid.Template.BestFitColumns();
    var gridSize = tipGrid.TableElement.MinSize;
 
    var screenTip = new RadOffice2007ScreenTipElement{AutoSize = true};
 
    screenTip.CaptionLabel.Text = function.Name;
    screenTip.MainTextLabel.Text = "";
 
    screenTip.EnableCustomSize = true;
    screenTip.TipSize = new Size(gridWidth + 18, gridSize.Height);
 
    screenTip.MainTextLabel.Children.Add(tipGrid);
    screenTip.UpdateLayout();
 
    cell.ScreenTip = screenTip;
}


0
Jack
Telerik team
answered on 21 Nov 2012, 04:08 PM
Hi guys,

Yes, I confirm that there is an issue with the width of RadGridView when using my method. This can be corrected by using a custom RadGridViewElement and overriding its MeasureOverride method. Note that you should also set the EnableCustomSize property to false. Consider the sample below:
void button_ScreenTipNeeded(object sender, ScreenTipNeededEventArgs e)
{
    RadOffice2007ScreenTipElement screenTip = new RadOffice2007ScreenTipElement();
    screenTip.ThemeRole = "Office2010Silver";
    screenTip.CaptionLabel.Text = "This is a Screen Tip";
    screenTip.MainTextLabel.Text = "";
    screenTip.EnableCustomSize = false;
 
    RadGridViewElement grid = new CustomGrid();
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column1"));
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column2"));
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column3"));
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column4"));
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column5"));
    grid.Template.Columns.Add(new GridViewTextBoxColumn("Column6"));
    grid.Template.Rows.Add("1", "first");
    grid.Template.Rows.Add("2", "second");
    grid.Template.Rows.Add("3", "second");
    grid.Template.Rows.Add("4", "second");
    grid.Template.Rows.Add("5", "second");
    grid.Template.Rows.Add("6", "third");
    screenTip.MainTextLabel.Children.Add(grid);
             
    RadButtonElement button = (RadButtonElement)e.Item;
    button.ScreenTip = screenTip;           
}

public class CustomGrid : RadGridViewElement
{
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadGridViewElement);
        }
    }
 
    protected override SizeF MeasureOverride(SizeF availableSize)
    {
        SizeF desiredSize = base.MeasureOverride(new SizeF(float.PositiveInfinity, float.PositiveInfinity));
        return desiredSize;
    }
}

The only way to change the theme of RadGridView in screen tips is to change the whole application theme by setting the ApplicationThemeName property:
ThemeResolutionService.ApplicationThemeName = "TelerikMetro";

I hope this helps.

Greetings,
Jack
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Ian
Top achievements
Rank 1
answered on 30 Jan 2013, 09:14 PM
Hi Guys

The embedded gridview in a screentip is proving to be a very useful "peek at the data" tool for our UI. Thanks for your help so far.

There is one little niggle which I hope you will be able to resolve.

I'm using the following code to generate the screentip when ScreenTipNeeded fires...

private void DisplayGroupOSpecValues(GridCommandCellElement cell)
{
    var row = cell.RowInfo;
 
    var tag = cell.Children[0].Tag;
    if (tag.GetType() != typeof(string)) return;
    if ((string)tag == "Empty") return;
 
    OrderSpecificationType spec;
 
    var oSpecs = ((InstrumentGroup)row.Tag).OrderSpecifications;
 
    var tipGrid = new RadCustomGridViewElement
    {
        ShowGroupPanel = false,
    };
 
    tipGrid.Template.AllowAddNewRow = false;
    tipGrid.Template.AllowColumnChooser = false;
    tipGrid.Template.AllowColumnHeaderContextMenu = false;
    tipGrid.Template.AllowColumnReorder = false;
    tipGrid.Template.AllowDeleteRow = false;
    tipGrid.Template.AllowDragToGroup = false;
    tipGrid.Template.AllowEditRow = false;
    tipGrid.Template.AllowRowReorder = false;
    tipGrid.Template.AllowRowResize = false;
    tipGrid.Template.EnableGrouping = false;
    tipGrid.TableElement.EnableHotTracking = false;
    tipGrid.Template.EnableSorting = false;
    tipGrid.Template.ShowRowHeaderColumn = false;
 
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Type") , AutoSizeMode = BestFitColumnMode.DisplayedDataCells, AutoEllipsis = false});
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Qty"), AutoSizeMode = BestFitColumnMode.DisplayedDataCells, AutoEllipsis = false });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "TIF"), AutoSizeMode = BestFitColumnMode.DisplayedDataCells, AutoEllipsis = false });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Style"), AutoSizeMode = BestFitColumnMode.DisplayedDataCells, AutoEllipsis = false });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Trigger"), AutoSizeMode = BestFitColumnMode.DisplayedDataCells, AutoEllipsis = false });
    tipGrid.Template.Columns.Add(new GridViewTextBoxColumn { HeaderText = string.Format("{0}", "Lapse"), AutoSizeMode = BestFitColumnMode.DisplayedDataCells, AutoEllipsis = false });
 
    foreach (var oSpec in oSpecs)
    {
        var rowInfo = tipGrid.Template.Rows.AddNew();
        switch (cell.ColumnIndex)
        {
            case 1:
                SetGridValues(oSpec, rowInfo, false);
                break;
            case 2:
                SetGridValues(oSpec, rowInfo, false);
                break;
            case 3:
                SetGridValues(oSpec, rowInfo, false);
                break;
            case 4:
                SetGridValues(oSpec, rowInfo, false);
                break;
            case 5:
                SetGridValues(oSpec, rowInfo, true);
                break;
        }
    }
 
    tipGrid.CurrentRow = null;
    tipGrid.Template.BestFitColumns();
 
    var screenTip = new RadOffice2007ScreenTipElement { EnableCustomSize = false };
    screenTip.CaptionLabel.Text = ((InstrumentGroup)row.Tag).Name;
    screenTip.MainTextLabel.Text = "";
    screenTip.MainTextLabel.Children.Add(tipGrid);
    tipGrid.Template.Refresh();
 
    ((RadButtonElement)cell.Children[0]).ScreenTip = screenTip;
}

The problem is that the BestFitColumnsMode.DisplayedDataCells setting only works the first time the mouse is hovered over the CommandCell after that any further use of the event and the embedded grid code shows a grid with some of the text in the cells cut off as the columns are no longer being properly fitted.

This one has me stumped as I am creating a new grid and screentip each time the event fires and would expect the behaviour to be "brand new" each time as well.

All help gratefully received.
Regards
Ian Carson
0
Jack
Telerik team
answered on 01 Feb 2013, 12:24 PM
Hello Ian,

Thank you for writing me back.

That is strange. I see in your code that you are creating a new instance of RadGridViewElement every time and the screen tip instance is also recreated. I tested the same scenario and it works OK on my side. Please, could you send me your application. Maybe there is something else that causes the issue.

I am looking forward to your reply.
 
Greetings,
Jack
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Ian
Top achievements
Rank 1
answered on 01 Feb 2013, 01:37 PM
Hi Jack

Thanks for the reply. Unfortunately the app is proprietary so I won't be able to send it.

What were your avenues of thought? Perhaps I can send you the pieces required to aid your exploration.

regards
Ian  Carson
0
Jack
Telerik team
answered on 06 Feb 2013, 12:39 PM
Hello Ian,

We are ready to sign a non-disclosure agreement (NDA) if necessary. However, the best option is to send us a sample application where the issue can be reproduced. This will allow us to investigate the issue in detail and provide you with a proper solution. Note that you have to open a new support ticket in order to be able to attach a sample project.

I am looking forward to your reply.
 
Kind regards,
Jack
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Ian
Top achievements
Rank 1
answered on 07 Feb 2013, 02:00 AM
Hi Jack

I have opened a support ticket and attached a sample project which reproduces the issue.

Thanks for your help

Regards
Ian
0
Jack
Telerik team
answered on 08 Feb 2013, 10:58 AM
Hi Ian,

Thank you for sending me your code. I analysed your application and I found that it uses an old version of our controls. Our current release is Q3 2012 SP1 and I was not able to reproduce the issue when using this version. My recommendation is to try our latest release.

If you have other questions, do not hesitate to ask.
 
Regards,
Jack
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
GridView
Asked by
Ian
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Jack
Telerik team
Share this question
or