Solved

how to disable datagrid auto-adjustable column width?

Posted on 2007-03-26
1
367 Views
Last Modified: 2013-11-07
Hi, experts,

I want to disable the column width auto-adjustable feature of a datagrid. That is the default behavior when users double-click the column divider line on the row header and the width of that column will adjust to fit the max length of its content.

Using HitTest, my following code tried to detect the double click on the divider line, and somehow to disbale the resize, but it is not working. I could not even get to Exit Sub part.

By the way, this is a vs2003 datagrid, not vs2005 datagridView. Thanks!

 Private Sub dgbyCSR_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgbyCSR.DoubleClick
            Try
                Dim pt As System.Drawing.Point = dgbyCSR.PointToClient(Windows.Forms.Cursor.Position)
                Dim hti As DataGrid.HitTestInfo = dgbyCSR.HitTest(pt)
                If hti.Type = DataGrid.HitTestType.ColumnResize Then
                    'do nothing to prevent users from auto-adjust column width
                    Exit Sub
                Else 'do other normal stuff
                End if
End Sub

Or,

I guess I could ask my question in another way. Most of hittest samples I got are firing off from datagrid_MouseUp/Down event, which has this args,
ByVal e As System.Windows.Forms.MouseEventArgs
however, on the datagrid_doubleClick, the default args is System.EventArgs.

I am not sure how would you detect a double click on the column divider. If I could have that figure out, only then, my original question is valid.
0
Comment
Question by:ommer
1 Comment
 
LVL 21

Accepted Solution

by:
theGhost_k8 earned 125 total points
ID: 18794078
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21260160.html?sfQueryTermInfo=1+adjust+auto+column+datagrid#a12946736
You would need this:

Public Class dataGridNoResize
    Inherits DataGrid

    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim hti As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y)

        If hti.Type = DataGrid.HitTestType.ColumnResize Then
            Exit Sub 'no baseclass call
        End If

        MyBase.OnMouseMove(e)
    End Sub



    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim hti As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y)

        If hti.Type = DataGrid.HitTestType.ColumnResize Then
            Exit Sub 'no baseclass call
        End If

        MyBase.OnMouseDown(e)

    End Sub
End Class


If you include this class, then you would need to redo 2 lines in the windows generated code as follows:

    Friend WithEvents DataGrid1 As dataGridNoResize
and
        Me.DataGrid1 = New dataGridNoResize
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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