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

GridView的RowDataBound事件

RowDataBound event of GridView

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


有一个属性 ShowCellToolTips [DataGridView控件中的Window> ^ ].
试试这个.
There is a property ShowCellToolTips [^] in DataGridView control.
Try this.


在GridView for Datarow的RowDataBound事件中写

In RowDataBound event of GridView for Datarow write

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



问候
Praveen



Regards
Praveen