C #: show tooltip in sub

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

What I could not do was show a tooltip. 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"); } 

I would like to get the hexadecimal value of the code, which will be displayed in a tooltip above the decimal value, but it is displayed above the name.

I was not able to get anything that I was trying to work (for example, trying to get the subtype coordinates). I would appreciate any suggestion.

+4
source share
1 answer

this code works for me

 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 event from the list:

 void lstList_MouseMove(object sender, MouseEventArgs e) { ListViewItem item = lstList.GetItemAt(eX, eY); ListViewHitTestInfo info = lstList.HitTest(eX, eY); 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, ""); } } 
+5
source

All Articles