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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Getting ListView Header Text

Getting ListView Header Text

Scheduled Pinned Locked Moved C#
help
5 Posts 2 Posters 2 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.
  • F Offline
    F Offline
    Farhan Ali
    wrote on last edited by
    #1

    Asalam o Alaikum: I am getting problem while finding the ListView Header text through SendMessage() Does any body Knows Thanx

    S 1 Reply Last reply
    0
    • F Farhan Ali

      Asalam o Alaikum: I am getting problem while finding the ListView Header text through SendMessage() Does any body Knows Thanx

      S Offline
      S Offline
      Svetlin Panayotov
      wrote on last edited by
      #2

      Is there any particular reason you are using SendMessage() instead of myListView.Columns[columnIndex].Text

      F 1 Reply Last reply
      0
      • S Svetlin Panayotov

        Is there any particular reason you are using SendMessage() instead of myListView.Columns[columnIndex].Text

        F Offline
        F Offline
        Farhan Ali
        wrote on last edited by
        #3

        Actually i am trying to get ListView Header text from other application. So i have to use SendMessage(); there are other functions like LVM_GETITEM ,i am in a search of this kind of function. Thanx

        S 1 Reply Last reply
        0
        • F Farhan Ali

          Actually i am trying to get ListView Header text from other application. So i have to use SendMessage(); there are other functions like LVM_GETITEM ,i am in a search of this kind of function. Thanx

          S Offline
          S Offline
          Svetlin Panayotov
          wrote on last edited by
          #4

          Here's a sample on how to do it (just copy / paste the code and build it) public const UInt32 LVM_FIRST = 0x1000; public const UInt32 LVM_GETCOLUMN = LVM_FIRST + 95; public const UInt32 LVCF_TEXT = 0x0004; [StructLayout(LayoutKind.Sequential, Pack=8, CharSet=CharSet.Auto)] public struct LVCOLUMN { public uint mask; public int fmt; public int cx; public IntPtr pszText; public int cchTextMax; public int iSubItem; public int iImage; public int iOrder; } [DllImport("User32", CharSet=CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, ref LVCOLUMN lParam); private void button1_Click(object sender, System.EventArgs e) { int iTextSize = 255; IntPtr pText = Marshal.AllocHGlobal(iTextSize); LVCOLUMN lCol = new LVCOLUMN(); lCol.mask = LVCF_TEXT; lCol.cchTextMax = iTextSize - 1; lCol.pszText = pText; uint nIndex = 0; SendMessage(listView1.Handle, LVM_GETCOLUMN, nIndex, ref lCol); System.Diagnostics.Trace.WriteLine(Marshal.PtrToStringAuto(pText)); Marshal.FreeHGlobal(pText); } } } I hope that not naming my controls properly will not bother you :) The demo uses list view on the same form, but I assume you already know how to get the handle of the listview, and replace it in the code above. Cheers, Svetlin

          F 1 Reply Last reply
          0
          • S Svetlin Panayotov

            Here's a sample on how to do it (just copy / paste the code and build it) public const UInt32 LVM_FIRST = 0x1000; public const UInt32 LVM_GETCOLUMN = LVM_FIRST + 95; public const UInt32 LVCF_TEXT = 0x0004; [StructLayout(LayoutKind.Sequential, Pack=8, CharSet=CharSet.Auto)] public struct LVCOLUMN { public uint mask; public int fmt; public int cx; public IntPtr pszText; public int cchTextMax; public int iSubItem; public int iImage; public int iOrder; } [DllImport("User32", CharSet=CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, ref LVCOLUMN lParam); private void button1_Click(object sender, System.EventArgs e) { int iTextSize = 255; IntPtr pText = Marshal.AllocHGlobal(iTextSize); LVCOLUMN lCol = new LVCOLUMN(); lCol.mask = LVCF_TEXT; lCol.cchTextMax = iTextSize - 1; lCol.pszText = pText; uint nIndex = 0; SendMessage(listView1.Handle, LVM_GETCOLUMN, nIndex, ref lCol); System.Diagnostics.Trace.WriteLine(Marshal.PtrToStringAuto(pText)); Marshal.FreeHGlobal(pText); } } } I hope that not naming my controls properly will not bother you :) The demo uses list view on the same form, but I assume you already know how to get the handle of the listview, and replace it in the code above. Cheers, Svetlin

            F Offline
            F Offline
            Farhan Ali
            wrote on last edited by
            #5

            Thank you for ur reply .this code is working fine but when i pass the handle of the listview from some other application it does not return anything can you have any idea please Thanx

            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