?
Solved

how to disable datagrid auto-adjustable column width?

Posted on 2007-03-26
1
Medium Priority
?
384 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:
K V earned 500 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

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.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

862 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