1

I am displaying some large text in a System.Web.UI.WebControls.Gridview control (integrated in an ASP.NET web page) and I ended up showing the whole text only in a tooltip:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    string bigText = e.Row.Cells[5].Text;
    if (e.Row.Cells[5].Text.Length >= 100)
    {
        e.Row.Cells[5].Text = e.Row.Cells[5].Text.Substring(0, 100) + "...";
        e.Row.Cells[5].ToolTip = bigText;
    }
}

(don't mind the code, it's just an example of what I did)

The thing is that I would want users to be able to copy all the text and use it eventually. Even more, the tooltip does not really show all the text if it's huge so being able to copy all the text would be of great help.

Can I do this from the tooltip? Or do I have to implement something else?

The functionality I want is somewhat similar with copying error texts from the datatip in the Visual Studio debugger (althought I would live skipping the Copy Value part).

Coral Doe
  • 1,925
  • 3
  • 19
  • 36

2 Answers2

1

Unfortunately, the default Tooltips do not offer the right-click -> Copy feature that DataTips feature. See here:

http://social.msdn.microsoft.com/Forums/en-US/c508bc09-cae5-4a95-9680-bf77eef9c294/copy-tooltip-content

Unless you can find a custom third-party control, I'm afraid you'll have to roll your own solution. A possibility may be to show a context menu when right-clicking a GridView row.

These SO questions cover displaying context menus for specific rows:

right click context menu for datagridview

DataGridView right-click menu/copy example?

Community
  • 1
  • 1
Dave R.
  • 7,206
  • 3
  • 30
  • 52
0

How about you link a button press to trigger saving text to a clipboard.

You'll need to reference System.Windows and add the namespace to the code.

Clipboard.SetText(SelectedValue.Tooltip.Text)

The above is obviously sudo code but that would solve the problem?

Coral Doe
  • 1,925
  • 3
  • 19
  • 36
Ash Robinson
  • 41
  • 1
  • 1
  • 9
  • This could be a pottential solution to my problem, it would provide the functionality I want. But I would like more a solution that does not involve adding extra buttons or other controls to my gridview. – Coral Doe Aug 21 '13 at 15:26
  • How about looking for an event that fires when you change cell? I can't remember it but I'm sure there is one. – Ash Robinson Aug 21 '13 at 16:12