数据在Gridview的工具提示中被截断 [英] Data get truncated in tooltip of Gridview
问题描述
我想显示GridView每一行的工具提示。我为此写了以下代码:
Grid的RowDataBound事件:
DataSet dtset = new DataSet( root);
dtset.ReadXml(Server.MapPath( @ 〜\ XMLFILE.xml) );
尝试
{
if (dtset!= null & dtset.Tables.Count > 0 )
{
for ( int colIndex = 0 ; colIndex < e.Row.Cells.Count; colIndex ++)
{
// 执行数据库查找
// string ttString =数据库查找结果;
// strReturn = strReturn.Replace([Page],strPage);
DataRow [] dr = dtset.Tables [ 0 ]。选择( Measure =' + e.Row.Cells [ 0 ]。Text.ToUpper()+ ');
if (dr!= null && dr.Length> 0)
{
// 第一种方法
e.Row.Cells [ colIndex] .Attributes.Add( title,Convert.ToString(dr [ 0 ] [ 1 ]));
// 第二种方法
e.Row.ToolTip = Convert.ToString( dr [ 0 ] [ 1 ]);
}
}
}
}
我正在阅读XML文件中的所有工具提示,并根据标题将它们分配给Row。
现在我的问题是我有在工具提示和上面的代码中显示的文本工作正常但字符串因长度而被截断。字符串的长度几乎是250-300个字符,包括换行符。
任何想法为什么字符串会自行截断,可以做些什么来对它进行排序out?
使用绘图的示例: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.draw.aspx [ ^ ]
我认为你需要测量要显示的文本而不进行任何截断并允许换行(如果屏幕或工具提示弹出窗口太长)。
' 确定button2工具提示的正确大小。
私有 Sub toolTip1_Popup( ByVal 发件人作为系统。对象,_
ByVal e As PopupEventArgs) Handles toolTip1。弹出窗口
如果 e.AssociatedControl button2 然后
Dim f 作为 新字体( Tahoma, 9 )
尝试
e.ToolTipSize = TextRenderer.MeasureText(_
toolTip1。 GetToolTip(e.AssociatedControl),f)
最后
f.Dispose()
结束 尝试
结束 如果
结束 Sub
我从这里取出代码: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.ownerdraw。 aspx [ ^ ]
I want to show tooltip of each row of GridView. For which i have written following code on
RowDataBound event of Grid :
DataSet dtset = new DataSet("root");
dtset.ReadXml(Server.MapPath(@"~\XMLFILE.xml"));
try
{
if (dtset != null & dtset.Tables.Count > 0)
{
for (int colIndex = 0; colIndex < e.Row.Cells.Count; colIndex++)
{
// Do database lookup
//string ttString = "Result of database lookup";
// strReturn = strReturn.Replace("[Page]", strPage);
DataRow [] dr = dtset.Tables[0].Select("Measure ='"+e.Row.Cells[0].Text.ToUpper()+"'");
if(dr!= null && dr.Length >0)
{
// First approach
e.Row.Cells[colIndex].Attributes.Add("title", Convert.ToString(dr[0][1]));
// Second approach
e.Row.ToolTip = Convert.ToString(dr[0][1]);
}
}
}
}
I am reading all tool tips from XML file and assigning them to Row as per their title.
Now my Problem is I have along text to show in tooltip and above code works fine but string is truncated because of length. Length of string is almost 250-300 characters including new line.
Any idea why string is truncated on its own and what can be done to sort it out ?
Example using draw: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.draw.aspx[^]
I think essentially that you need to measure the text to display without any truncating and allow wrap (if too long for the screen or tooltip popup).
' Determines the correct size for the button2 ToolTip. Private Sub toolTip1_Popup(ByVal sender As System.Object, _ ByVal e As PopupEventArgs) Handles toolTip1.Popup If e.AssociatedControl Is button2 Then Dim f As New Font("Tahoma", 9) Try e.ToolTipSize = TextRenderer.MeasureText( _ toolTip1.GetToolTip(e.AssociatedControl), f) Finally f.Dispose() End Try End If End Sub
I pulled that code from here: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.ownerdraw.aspx[^]
这篇关于数据在Gridview的工具提示中被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!