Solved

how to disable datagrid auto-adjustable column width?

Posted on 2007-03-26
1
365 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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

7 Experts available now in Live!

Get 1:1 Help Now