本文介绍了DataGridView单元格内容工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关如何显示datagridview单元中内容的toolTip的帮助.默认情况下设置为true的内置ShowCellContent属性不能很好地工作,它不能为每个单元格显示内容,所以有一些代码可以用来使之工作

感谢

I need help on how to show toolTip of content from datagridview cell. the built in ShowCellContent property which is set to true by default is not working well, it doesnt show for every cell the content, so is there some code which I can use to make this work

thanks

推荐答案

protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
            if (e.Row.Cells[i].Controls.Count == 0)
            {
                e.Row.Cells[i].ToolTip = e.Row.Cells[i].Text;
            }
            else
            {
                e.Row.Cells[i].ToolTip = GetObjectType(e.Row.Cells[i].Controls[1]);
            }
        }
    }
}

private String GetObjectType(Control ctrl)
{
    switch (ctrl.GetType().Name)
    {
        case "Label":
            return ((Label)ctrl).Text;
        case "TextBox":
            return ((TextBox)ctrl).Text;
    }
    return "";
}



问候,
Senthil



Regards,
Senthil



e.Row.Cells[0].ToolTip = "Your ToolTip Text";



问候
Praveen



Regards
Praveen


这篇关于DataGridView单元格内容工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 04:18