Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable Column Resizing in ListView

Posted on 2006-11-13
8
Medium Priority
?
588 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 900 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Introduction to Processes
Starting up a Project

715 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