Solved

how to disable datagrid auto-adjustable column width?

Posted on 2007-03-26
1
377 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:
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

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 document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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