Solved

Disable Column Resizing in ListView

Posted on 2006-11-13
8
579 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
 
LVL 2

Expert Comment

by:amiableansari
ID: 17929277


i guess you override winproc in form class instead of the header class....
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now