?
Solved

how to disable datagrid auto-adjustable column width?

Posted on 2007-03-26
1
Medium Priority
?
381 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
[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
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

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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