Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Text in a listview column

Text in a listview column

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Haim Yulzari
    wrote on last edited by
    #1

    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!

    A 1 Reply Last reply
    0
    • H Haim Yulzari

      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!

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      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);

      H 1 Reply Last reply
      0
      • A Anonymous

        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);

        H Offline
        H Offline
        Haim Yulzari
        wrote on last edited by
        #3

        WOW! Thanks a lot!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups