473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Frustrated with preventing user resizing datagrid columns, please

Hi there,

I've tried everything that I know to prevent usre resizing datagrid columns,
but nothing works. Following are the code that I used. Please tell me
what's wrong with them. Thank you.

P.S.: dg is datagrid

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
Dim hti As DataGrid.HitTestInfo = me.dg.HitTest(New Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)
Dim hti As DataGrid.HitTestInfo = me.dg.HitTest(New Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseMove(e)
End Sub

Private Sub dg_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgPond.MouseDown
Dim hti As DataGrid.HitTestInfo = Me.dg.HitTest(New
Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseDown(e)
End Sub

Private Sub dg_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgPond.MouseMove
Dim hti As DataGrid.HitTestInfo = Me.dg.HitTest(New Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseMove(e)
End Sub
Nov 21 '05 #1
2 1747
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 ConfirmDeleteDataGrid

Inherits DataGrid

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

Private Const WM_KEYDOWN = &H100

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

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

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

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

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

Return MyBase.PreProcessMessage(msg)

End Function

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

Dim pt As Point

Dim hti As DataGrid.HitTestInfo

pt = Me.PointToClient(Cursor.Position)

hti = Me.HitTest(pt)

If keyData = Keys.Delete Then

If hti.Type = Me.HitTestType.RowHeader Then

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

MessageBoxButtons.YesNo) = DialogResult.No Then

Return True

Else

RaiseEvent DeletedRow(Me, New EventArgs)

End If

End If

End If

Return MyBase.ProcessDialogKey(keyData)

End Function

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)

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

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseDown(e)

End Sub

Public Sub New()

Trace.WriteLine(Me.VertScrollBar.Visible.ToString)

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)

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

If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type =
DataGrid.HitTestType.RowResize Then

Return 'no baseclass call

End If

MyBase.OnMouseMove(e)

End Sub
End Class

Ken

-------------------------------
"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
Hi there,

I've tried everything that I know to prevent usre resizing datagrid columns,
but nothing works. Following are the code that I used. Please tell me
what's wrong with them. Thank you.

P.S.: dg is datagrid

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
Dim hti As DataGrid.HitTestInfo = me.dg.HitTest(New Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)
Dim hti As DataGrid.HitTestInfo = me.dg.HitTest(New Point(e.X,
e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseMove(e)
End Sub

Private Sub dg_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgPond.MouseDown
Dim hti As DataGrid.HitTestInfo = Me.dg.HitTest(New
Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseDown(e)
End Sub

Private Sub dg_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgPond.MouseMove
Dim hti As DataGrid.HitTestInfo = Me.dg.HitTest(New Point(e.X, e.Y))
If hti.Type = DataGrid.HitTestType.ColumnResize Then
Return 'no baseclass call
End If
MyBase.OnMouseMove(e)
End Sub

Nov 21 '05 #2
Thank you so much Mr. Tucker. You solved my problem. "Inherited" is the key
that I missed.

Thanks again.

Nina
Nov 21 '05 #3

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

Similar topics

3
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable(...
0
by: Jason | last post by:
I am pretty new to C# so bare with me... The design of my website utilizes tables on every page that look almost identical, save the data they are displaying. I have written the code to create...
0
by: Zi | last post by:
I have a user control within a data grid. I am binding the user control to one of the values from the data grid. The data grid implements paging. It is all working ok for the first page but once i...
2
by: Marty McDonald | last post by:
When setting certain datagrid properties with the IDE (as in the property window), they don't seem to take effect. For instance, Font Name. So I have to set these via code-behind at the cell...
0
by: Paul | last post by:
Hi I have a datagrid with two different hyperlink columns. The columns open up a new window as the target is set to _blank for both. The windows are different sizes (one large, one small) and I...
3
by: Agnes | last post by:
In textbox, I know I can set e.handled = false in keypressevent , So I can restrict the user to input some invalid character or disallow the user to input any thing Now, in datagrid, there are 3...
9
by: cjobes | last post by:
Hi all, I don't know how many hours I've spend on this but I don't want to give up and there has to be a way of doing this. Here is what I'm trying to do: I have a small Windows Forms app...
1
by: margant | last post by:
Dear Professionals, I have placed my datagrid : .... <asp:Datagrid ID="DGEdu" runat="server" OnDeleteCommand="DGEdu_Remove" OnItemDataBound="DGEdu_ItemDataBound"...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.