显示工具提示中的datagridview行的每一个项目,当鼠标在它上面 [英] Showing tool tip for every item in datagridview row when mouse is above it

查看:427
本文介绍了显示工具提示中的datagridview行的每一个项目,当鼠标在它上面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么能显示工具提示 datagridview的的每个项目在 datagridview的当您通过在项目悬停鼠标该特定行?

How can you show the tooltip for datagridview for every item in datagridview when you hover mouse over the item in that particular row?

我有表产品的列:

product name 
product price 
product description
product image ....

我有一个要求,我有一个 datagridview的列和我从数据库中获取这些:

I have a requirement that I have a datagridview with columns and I am getting these from database:

product name 
product price 
product image ....

现在我要显示这样的提示:如果我有鼠标的产品形象,产品说明会显示该产品。我想这样做的每一行。会有人请就这一个帮助?

Now I want to show the tooltip like this: if I have mouse over the product image, the product description will be displayed for that product. I want to do this for every row. Would anyone please help on this one?

推荐答案

看看的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.tooltiptext.aspx">DataGridViewCell.ToolTipText物业并使用DataGridView中的 CellFormatting 事件来设置该属性值。您可以使用该事件的 DataGridViewCellFormattingEventArgs 参数:columnIndex 属性来确定该事件被解雇的列你想设置的工具小费如果是使用事件的 rowIndex位置指定刀尖的价值。

Take a look at the DataGridViewCell.ToolTipText property and use the DataGridView's CellFormatting event to set this property value. You can use the event's DataGridViewCellFormattingEventArgs ColumnIndex property to determine if the event is firing for the column you want to set a tool tip for and if so use the event's RowIndex to specify that tool tip's value.

MSDN文章我联系中的样品有使用的一个很好的例子,但你的code可能看起来是这样的:

The sample in the MSDN article I linked have a fine example of usage, but your code might look something like this:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
    if (e.ColumnIndex == dataGridView1.Columns[nameOrIndexOfYourImageColumn].Index) {
        var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        // Set the Cell's ToolTipText.  In this case we're retrieving the value stored in 
        // another cell in the same row (see my note below).
        cell.ToolTipText = dataGridView1.Rows[e.RowIndex].Cells[nameOrIndexOfYourDescriptionColumn].Value.ToString();
    }
}

其中:
  nameOrIndexOfYou​​rImageColumn =列名的image列或索引值   nameOrIndexOfYou​​rDescriptionColumn =列名或索引值与你的描述数据。

Where:
nameOrIndexOfYourImageColumn = the column name or index value of your image column nameOrIndexOfYourDescriptionColumn = the column name or index value with your description data.

请注意:你会需要一些方法来检索行的描述数据。要做到这一点的常用方法是有它列在你的DataGridView,但要因为你不希望显示此列设置其可见属性设置为false。然而有其他的选择。

Note: that you'll need some way to retrieve a row's Description data. A common way to do this is to have a column for it in your DataGridView, but make since you don't want to display this column set its Visible property to false. There are other options however.

这篇关于显示工具提示中的datagridview行的每一个项目,当鼠标在它上面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆