简体   繁体   English

如何使用ListBox中的项目列表对GridView的标题进行工具提示

[英]How to tooltip the headers of the GridView using the list of items in ListBox

I have a GridView and a list of items in a ListBox . 我有一个GridViewListBox中的项目ListBox Excluding the first column in the GridView . 不包括GridView的第一列。

I want to tooltip each and every header with the corresponding item in the ListBox . 我想用ListBox的相应项目对每个标题进行工具提示。 I mean the tooltip for GridView2.Columns[i].HeaderText = ListBox.Items[i].Tostring() . 我的意思是GridView2.Columns[i].HeaderText = ListBox.Items[i].Tostring()的工具提示。

Here is what I have tried: 这是我尝试过的:

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            for (int i = 1; i < GridView2.Columns.Count; i++)
            {
                String header = GridView2.Columns[i].HeaderText; 

                if (header.Length != 0)
                {
                   e.Row.Cells[i].ToolTip = ListBox4.Items[i].ToString().Trim();
                }
            }
        }
    }

This is giving me an exception error: Index was out of range. 这给了我一个异常错误:索引超出范围。 Must be non-negative and less than the size of the collection. 必须为非负数并且小于集合的大小。

Kindly help. 请帮助。 Thank you. 谢谢。

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        for (int i = 1; i < GridView2.Columns.Count; i++)
        {
            String header = GridView2.Columns[i].HeaderText; 

            if (header.Length != 0)
            {
               e.Row.Cells[i+1].ToolTip = ListBox4.Items[i].ToString().Trim();
            }
        }
    }
}

Just suppose to use Cells[i+1] instead of Cells[i] 只是假设使用Cells [i + 1]而不是Cells [i]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM