473,857 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable datagrid column resize

Hi,
I need to disable the resizing of a datagrid.
I have tried al day and no luck.
Any Ideas?

Thanks.

George.
Nov 21 '05 #1
1 2931
Hi,

You need to create an inherited datagrid for that. Here is the code
for one that will raise an event to let you the user is about to delete a
row. Also prevents the user from resizing a row or column.

Public Class ConfirmDeleteDa taGrid

Inherits DataGrid

Public Event DeletedRow(ByVa l sender As Object, ByVal e As EventArgs)

Private Const WM_KEYDOWN = &H100

Public Overrides Function PreProcessMessa ge(ByRef msg As
System.Windows. Forms.Message) As Boolean

Dim keyCode As Keys = CType((msg.WPar am.ToInt32 And Keys.KeyCode), Keys)

If msg.Msg = WM_KEYDOWN And keyCode = Keys.Delete Then

If MessageBox.Show ("Delete This Row?", "Confirm Delete", _

MessageBoxButto ns.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

Return MyBase.PreProce ssMessage(msg)

End Function

Protected Overrides Function ProcessDialogKe y(ByVal keyData As
System.Windows. Forms.Keys) As Boolean

Dim pt As Point

Dim hti As DataGrid.HitTes tInfo

pt = Me.PointToClien t(Cursor.Positi on)

hti = Me.HitTest(pt)

If keyData = Keys.Delete Then

If hti.Type = Me.HitTestType. RowHeader Then

If MessageBox.Show ("Delete this row?", "Confirm Delete", _

MessageBoxButto ns.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

End If

Return MyBase.ProcessD ialogKey(keyDat a)

End Function

Protected Overrides Sub OnMouseDown(ByV al e As
System.Windows. Forms.MouseEven tArgs)

Dim hti As DataGrid.HitTes tInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTes tType.ColumnRes ize Or hti.Type =
DataGrid.HitTes tType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseD own(e)

End Sub

Public Sub New()

Trace.WriteLine (Me.VertScrollB ar.Visible.ToSt ring)

End Sub

Protected Overrides Sub OnMouseMove(ByV al e As
System.Windows. Forms.MouseEven tArgs)

Dim hti As DataGrid.HitTes tInfo = Me.HitTest(New Point(e.X, e.Y))

If hti.Type = DataGrid.HitTes tType.ColumnRes ize Or hti.Type =
DataGrid.HitTes tType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseM ove(e)

End Sub
End Class

Ken

-------------------------------

"Geroge D. Lake" <ge*********@cu artel15.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi,
I need to disable the resizing of a datagrid.
I have tried al day and no luck.
Any Ideas?

Thanks.

George.

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1737
by: Pietje de kort | last post by:
Hello, why is the System.Windows.Forms.DataGrid so un-customizable? I am trying to build a DataGrid that will resize it's last column when there is room left over (make it fill the total clientwidth). I am almost capable of doing so by the following actions: - Create a custom DataGridTableStyle called AutoResizeDataGridTableStyle - Hook up the OnResize and OnDataSourceChanged from the AutoResizeDataGridTableStyle to their respected...
3
4272
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
0
1668
by: Stuart Ferguson | last post by:
I am currently writing a windows application which uses DataGrid components to display some data. I am wanting to allow the user to resize the columns to display data that is longer than the column width however i would like to restrict the user so they cant stretch the rows. I know this can be done using a list view but could only see a solution using the MouseDown event and Windows API calls. Is there a simpler method than this ? ...
3
1701
by: Brian Mitchell | last post by:
I hate to ask this question because I'm sure it's been asked before, but how do you automatically resize the columns in a datagrid when the form is resized? Thanks!!
4
2736
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all my rows back to their defaults. I populate the datagrid, resize it accordingly and it works fine...just when I click the headers is when it messes up. It would be fine if I could run my autosizing again after the sorting is done since there...
8
15192
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code that seems to work for 99% of the cases where I need to disable datagrid column sorting: Private Sub datagrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagrid.MouseDown Dim pt As New Point(e.X,...
1
1864
by: garyusenet | last post by:
I'm following a sql/vb tutorial which contains the following code which is meant to resize the datagrid view so that the columns take the correct width for the content within them. It doesn't work the syntax seems to be nonsense according to VS2005 so can someone suggest what I need to replace it with? Thanks...
1
7157
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on the first column in the grid only. I havent found a way to reliably do this yet. I tried putting the following code in the datagrid's mouse down event Dim hti As DataGrid.HitTestInfo
0
1342
by: ashinamdev | last post by:
Hi I have a probelm I am using the datagrid control in my asp.net web page. I want to resize the datagrid column at runtime. User can be able to resize the column width according to his requirment at run time. Pls solve this problem. Ashish
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10711
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7940
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.