C#中:子项目上显示工具提示 [英] c#: show tooltip on subitem

查看:145
本文介绍了C#中:子项目上显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,并在列(不是第一个)之一,我想显示一个错误code。

I have a listview, and in one of the columns (not the first) I want to display an error code.

我还没有能够做的就是工具提示中显示。我有

What I haven't been able to do is get the ToolTip to display. I have

this.lstList.ShowItemToolTips = true;
...
ListViewItem value = lstList.Items.Add(name, name, 0);
...
if (lstList.Columns.Contains(lstColErrorCode))
{                                
  value.SubItems.Add(new ListViewItem.ListViewSubItem(value, errorCode.ToString()));
  value.ToolTipText = errorCode.ToString("X");
}

我想获得code的十六进制值以上的十进制值的工具提示中显示,但它显示的名字上面。

I would like to get the hex value of the code to be shown on the tooltip above the decimal value, but it shows above the name.

我一直没能得到任何我想工作(如试图让子项的坐标)。我想AP preciate任何建议。

I haven't been able to get anything I tried to work (like trying to get the coordinates of the subitem). I would appreciate any suggestion.

推荐答案

这code对我的作品

ToolTip toolTip1 = new ToolTip();

void initMethod()
{
    lstList.MouseMove += new MouseEventHandler(lstList_MouseMove);//mousemove handler
    this.lstList.ShowItemToolTips = true;            
    toolTip1.SetToolTip(lstList,"");// init the tooltip
    ...
    ListViewItem value = lstList.Items.Add(name, name, 0);
    ...
    if (lstList.Columns.Contains(lstColErrorCode))
    {                                
        ListViewItem.ListViewSubItem lvs =  value.SubItems.Add(new ListViewItem.ListViewSubItem(value, errorCode.ToString()));
        lvs.Tag = "mydecimal"; // only the decimal subitem will be tooltiped
    }
}

从列表视图MouseMove事件:

the mousemove event from the listview:

void lstList_MouseMove(object sender, MouseEventArgs e)
{
    ListViewItem item = lstList.GetItemAt(e.X, e.Y);
    ListViewHitTestInfo info = lstList.HitTest(e.X, e.Y);

    if ((item != null) && (info.SubItem != null) && (info.SubItem.Tag!=null) && (info.SubItem.Tag.ToString() == "mydecimal"))
    {
        toolTip1.SetToolTip(lstList,((decimal)info.SubItem.Text).ToString("X"));
    }
    else
    {
        toolTip1.SetToolTip(lstList, "");
    }
}

这篇关于C#中:子项目上显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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