Solved

Disable Column Resizing in ListView

Posted on 2006-11-13
8
583 Views
Last Modified: 2012-06-21
Hi again experts,

I'm using a lot of listviews and they really work for me, the problem is that i use my listviews with details view and the user can resize the colums..

All i need is to stop the resizing of the colums is there any way of doing this like we can do with the datagrid ?
0
Comment
Question by:MICROCAOS
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

by:amiableansari
ID: 17929094
0
 

Author Comment

by:MICROCAOS
ID: 17929133
i tried that allready it simply does not work here .. any ideas ?
0
 
LVL 2

Accepted Solution

by:
amiableansari earned 300 total points
ID: 17929270

this code is working fine...


''''
''declare this in class
'''''''
Private ListViewHeader1 As ListViewHeader

    Private Declare Function GetWindow Lib "user32" Alias "GetWindow" _
       (ByVal hwnd As IntPtr, ByVal wCmd As Integer) As IntPtr
    Private Const GW_CHILD As Integer = 5

    Dim SysHdr32Handle As IntPtr
''''''''

''add this in form load
'''''''
SysHdr32Handle = GetWindow(ListView1.Handle, GW_CHILD)  
        ListViewHeader1 = New ListViewHeader(SysHdr32Handle)
'''''''

''' add this class in the form class
'''''''''''
Private Class ListViewHeader
        Inherits System.Windows.Forms.NativeWindow
        Private ptrHWnd As IntPtr

        Protected Overrides Sub WndProc(ByRef m _
          As System.Windows.Forms.Message)
            Select Case m.Msg
                Case Is = &H20  ' WM_SETCURSOR
                    m.Msg = 0
                Case Is = &H201  ' WM_LBUTTONDOWN
                    m.Msg = 0
            End Select

            MyBase.WndProc(m)
        End Sub

        Protected Overrides Sub Finalize()
            Me.ReleaseHandle()
            MyBase.Finalize()
        End Sub

        Public Sub New(ByVal ControlHandle As IntPtr)
            ptrHWnd = ControlHandle
            Me.AssignHandle(ptrHWnd)
        End Sub
    End Class
''''''''''
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:amiableansari
ID: 17929277


i guess you override winproc in form class instead of the header class....
0
 

Author Comment

by:MICROCAOS
ID: 17929750
well i tryed your code, and it simply does not do anything ...

On my form i got this sub ..

Public Class FrmComprasPRV
   Inherits System.Windows.Forms.Form
   Dim CHAVE As TIPOCHAVES
   Dim strSQL As String
   Public shtCODFOR, shtCODSFO, shtCODCMP As Short
   Dim ListViewHeader1 As ListViewHeader
   Dim SysHdr32Handle As IntPtr
..
.
.
.
.
.
.

Sub FILLIDENTIDADES()
      Dim lvwColuna As ColumnHeader
      Dim cnt As Integer
      Dim arrCOLUNAS(4) As String

      SysHdr32Handle = GetWindow(lsvAPP_TABIDE.Handle, GW_CHILD)
      ListViewHeader1 = New ListViewHeader(SysHdr32Handle)

      'DEFINICOES GERAIS DA LISTVIEW "lsvAPP_TABSFO"
      lsvAPP_TABIDE.View = View.Details
      lsvAPP_TABIDE.FullRowSelect = True
      lsvAPP_TABIDE.GridLines = False
      lsvAPP_TABIDE.CheckBoxes = True
      lsvAPP_TABIDE.HeaderStyle = ColumnHeaderStyle.Nonclickable
      lsvAPP_TABIDE.AllowColumnReorder = False
      lsvAPP_TABIDE.MultiSelect = False

      'ARRAY COM O NOME DAS COLUNAS
      arrCOLUNAS(0) = "Código"
      arrCOLUNAS(1) = "Produto"
      arrCOLUNAS(2) = "Quantidade"
      arrCOLUNAS(3) = "Tip. Compra"
      arrCOLUNAS(4) = "Gerada"

      'LIMPA AS LISTVIEWS
      lsvAPP_TABIDE.Clear()

      'CRIA AS COLUNAS
      lsvAPP_TABIDE.BeginUpdate()
      For cnt = 0 To arrCOLUNAS.GetUpperBound(0)

         lvwColuna = New ColumnHeader
         lvwColuna.Text = arrCOLUNAS(cnt)
         lsvAPP_TABIDE.Columns.Add(lvwColuna)
      Next
      lsvAPP_TABIDE.EndUpdate()

      'FORMATA AS COLUNAS
      lsvAPP_TABIDE.Columns(0).Width = 50
      lsvAPP_TABIDE.Columns(1).Width = 200
      lsvAPP_TABIDE.Columns(1).TextAlign = HorizontalAlignment.Center
.
.
.
.
.
End Class

and i put this on a module i have ...

   Public Declare Function GetWindow Lib "user32" Alias "GetWindow" _
      (ByVal hwnd As IntPtr, ByVal wCmd As Integer) As IntPtr
   Public Const GW_CHILD As Integer = 5

Public Class ListViewHeader
   Inherits System.Windows.Forms.NativeWindow
   Private ptrHWnd As IntPtr

   Protected Overrides Sub WndProc(ByRef m _
     As System.Windows.Forms.Message)
      Select Case m.Msg
         Case Is = &H20  ' WM_SETCURSOR
            m.Msg = 0
         Case Is = &H201  ' WM_LBUTTONDOWN
            m.Msg = 0
      End Select

      MyBase.WndProc(m)
   End Sub

   Protected Overrides Sub Finalize()
      Me.ReleaseHandle()
      MyBase.Finalize()
   End Sub

   Public Sub New(ByVal ControlHandle As IntPtr)
      ptrHWnd = ControlHandle
      Me.AssignHandle(ptrHWnd)
   End Sub
End Class

it does compile and stuff but i do not see any differences on the listview, we can still resize the columns...
0
 

Author Comment

by:MICROCAOS
ID: 17929778
Ok i got it working thanks... i just had to put the :
      SysHdr32Handle = GetWindow(lsvAPP_TABIDE.Handle, GW_CHILD)
      ListViewHeader1 = New ListViewHeader(SysHdr32Handle)
after the manual formatting of the columns and not before ..
Thanks amiableansari

Sub FILLIDENTIDADES()
      Dim lvwColuna As ColumnHeader
      Dim cnt As Integer
      Dim arrCOLUNAS(4) As String

      'DEFINICOES GERAIS DA LISTVIEW "lsvAPP_TABSFO"
      lsvAPP_TABIDE.View = View.Details
      lsvAPP_TABIDE.FullRowSelect = True
      lsvAPP_TABIDE.GridLines = False
      lsvAPP_TABIDE.CheckBoxes = True
      lsvAPP_TABIDE.HeaderStyle = ColumnHeaderStyle.Nonclickable
      lsvAPP_TABIDE.AllowColumnReorder = False
      lsvAPP_TABIDE.MultiSelect = False

      'ARRAY COM O NOME DAS COLUNAS
      arrCOLUNAS(0) = "Código"
      arrCOLUNAS(1) = "Produto"
      arrCOLUNAS(2) = "Quantidade"
      arrCOLUNAS(3) = "Tip. Compra"
      arrCOLUNAS(4) = "Gerada"

      'LIMPA AS LISTVIEWS
      lsvAPP_TABIDE.Clear()

      'CRIA AS COLUNAS
      lsvAPP_TABIDE.BeginUpdate()
      For cnt = 0 To arrCOLUNAS.GetUpperBound(0)

         lvwColuna = New ColumnHeader
         lvwColuna.Text = arrCOLUNAS(cnt)
         lsvAPP_TABIDE.Columns.Add(lvwColuna)
      Next
      lsvAPP_TABIDE.EndUpdate()

      'FORMATA AS COLUNAS
      lsvAPP_TABIDE.Columns(0).Width = 50
      lsvAPP_TABIDE.Columns(1).Width = 200
      lsvAPP_TABIDE.Columns(1).TextAlign = HorizontalAlignment.Center


      SysHdr32Handle = GetWindow(lsvAPP_TABIDE.Handle, GW_CHILD)
      ListViewHeader1 = New ListViewHeader(SysHdr32Handle)
0
 

Author Comment

by:MICROCAOS
ID: 17929866
wait eheheh not done yet eheh only one other problem, if you double click on the list view it resizes :-( .. any ideas ?
0
 
LVL 2

Expert Comment

by:amiableansari
ID: 17935955

add one more case

Case Is = &H203
                    m.Msg = 0
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question