Solved

Disable Column Resizing in ListView

Posted on 2006-11-13
8
582 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to send memory stream from ics Client To ics server ? 11 110
Base1 Encode/Decode 3 77
ASP/VB email question 4 35
Help Required 3 97
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

810 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