Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disable Column Resizing in ListView

Posted on 2006-11-13
8
Medium Priority
?
591 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

916 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