Text in a listview column
-
How can I programmatically determine whether a text in a listview column is longer than the column's width (i.e. displayed partially and ends with ellipsis)? Thanks!
-
How can I programmatically determine whether a text in a listview column is longer than the column's width (i.e. displayed partially and ends with ellipsis)? Thanks!
Try this protected virtual void GenericListControlMouseMove(object sender, MouseEventArgs e) { Point ptOnlist = Point.Empty; ListViewItem item = null; int subItemIndex = -1; int subItemTextWidth = -1; ListViewItem.ListViewSubItem curSubItem = null; try { // /// Check if no mouse button is down // if (e.Button == MouseButtons.None) { item = this.GetItemAt(e.X, e.Y); if (item != null) { subItemIndex = this.GetSubItemIndexFromPoint(item, new Point(e.X, e.Y)); if (subItemIndex != -1) { // /// Get the subItem on which the mouse pointer is present // curSubItem = item.SubItems[subItemIndex]; if (curSubItem != null) { if (curSubItem.Text.Length > 0) { subItemTextWidth = this.ListViewGetStringWidth(curSubItem.Text); if (subItemTextWidth != -1) { // /// MSDN:: ListViewSubItem text is padded 6 pixels on both side of the Text // subItemTextWidth += LISTVIEWSUBITEM_STRING_PADDING; if (subItemTextWidth > this.Columns[subItemIndex].Width) { if (curSubItem != this.lastSubItemHovered) { this.SetToolTipText(curSubItem.Text); this.lastSubItemHovered = curSubItem; } } else { this.SetToolTipText(string.Empty);
-
Try this protected virtual void GenericListControlMouseMove(object sender, MouseEventArgs e) { Point ptOnlist = Point.Empty; ListViewItem item = null; int subItemIndex = -1; int subItemTextWidth = -1; ListViewItem.ListViewSubItem curSubItem = null; try { // /// Check if no mouse button is down // if (e.Button == MouseButtons.None) { item = this.GetItemAt(e.X, e.Y); if (item != null) { subItemIndex = this.GetSubItemIndexFromPoint(item, new Point(e.X, e.Y)); if (subItemIndex != -1) { // /// Get the subItem on which the mouse pointer is present // curSubItem = item.SubItems[subItemIndex]; if (curSubItem != null) { if (curSubItem.Text.Length > 0) { subItemTextWidth = this.ListViewGetStringWidth(curSubItem.Text); if (subItemTextWidth != -1) { // /// MSDN:: ListViewSubItem text is padded 6 pixels on both side of the Text // subItemTextWidth += LISTVIEWSUBITEM_STRING_PADDING; if (subItemTextWidth > this.Columns[subItemIndex].Width) { if (curSubItem != this.lastSubItemHovered) { this.SetToolTipText(curSubItem.Text); this.lastSubItemHovered = curSubItem; } } else { this.SetToolTipText(string.Empty);
WOW! Thanks a lot!