473,379 Members | 1,257 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,379 software developers and data experts.

Drag and Drop Unhandled NullReferenceException

I have successfully implemented drag and drop in my application to
allow the reordering of columns by dragging and dropping them in the
same datagridvire (Net 2.0).

If i take it relatively slowly this works perfectly. However, if I
perform consecutive drag and drops quickly, the code seems to trip over
itself and throws the exception or other similar ones as per below.

The main problem is that no matter where I try to catch this exception,
I cannot. Not even in the application level unhandled exceptions event.
I have try and catch wrappers around every bit of code.

Can someone please advise;
1) how to catch this error
2) how to stop the drag and drop code falling over itself without using
crudemethods like timers.

Cheers
Dennis

This is the D&D code, though I don't think its actually relevant as it
works fine until done quickly.

Private Sub dgProjects_MouseDown(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles dgProjects.MouseDown
Dim hit As DataGridView.HitTestInfo = dgProjects.HitTest(e.X,
e.Y)
Dim dragSize As Size = SystemInformation.DragSize
Dim pointTopLeft As Point = New Point(e.X - (dragSize.Width /
2), e.Y - (dragSize.Height / 2))
dragRow = hit.RowIndex
dragBoxFromMouseDown = New Rectangle(pointTopLeft, dragSize)
End Sub

Private Sub dgProjects_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgProjects.MouseMove
Try
If e.Button = Windows.Forms.MouseButtons.Left Then
If Not dragBoxFromMouseDown.Contains(e.X, e.Y) Then
dgProjects.DoDragDrop(dgProjects.Rows(dragRow),
DragDropEffects.Move)
End If
End If
Catch
End Try
End Sub

Private Sub dgProjects_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgProjects.MouseUp
Try
dragBoxFromMouseDown = Rectangle.Empty
Catch
End Try
End Sub

Private Sub dgProjects_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles dgProjects.DragEnter
Try
e.Effect = DragDropEffects.Move
Catch
End Try
End Sub

Private Sub dgProjects_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles dgProjects.DragDrop
Try
Dim clientPoint As Point = dgProjects.PointToClient(New
Point(e.X, e.Y))
Dim hit As DataGridView.HitTestInfo =
dgProjects.HitTest(clientPoint.X, clientPoint.Y)
Dim myType As Type = GetType(DataGridViewRow)

If e.Data.GetData(myType).Index = hit.RowIndex Then Exit
Sub 'Dropped on self

Dim DestRowOrderID As Integer = dgProjects("OrderID",
hit.RowIndex).Value
Dim movedRow As DataGridViewRow =
dgProjects.Rows(e.Data.GetData(myType).Index)
Dim DestRowAboveOrderID As Integer
Dim OrderGap As Integer

If hit.RowIndex = 0 Then 'Dropped at top
DestRowAboveOrderID = 0
movedRow.Cells("OrderID").Value = DestRowOrderID + 20
OrderGap = 5
Else 'Dropped
DestRowAboveOrderID = dgProjects("OrderID",
hit.RowIndex - 1).Value
OrderGap = DestRowAboveOrderID - DestRowOrderID
movedRow.Cells("OrderID").Value = DestRowOrderID +
Int(OrderGap / 2)
End If

dgProjects.EndEdit()
Me.Validate()

ProjectRegisterBindingSource.Sort = "Active DESC, OrderID
DESC"
Try

ProjectRegisterTableAdapter.Update(dsProjects.Proj ectRegister)
dsProjects.AcceptChanges()
Catch ex As Exception
End Try

If OrderGap <= 2 Then
For Each dgvr As DataGridViewRow In dgProjects.Rows
dgvr.Cells("OrderID").Value = dgvr.Index * 20
Next
ProjectRegisterBindingSource.Sort = "Active DESC,
OrderID DESC"
Try

ProjectRegisterTableAdapter.Update(dsProjects.Proj ectRegister)
dsProjects.AcceptChanges()
Catch ex As Exception
End Try
End If
Catch
End Try
End Sub

************************
Here is the error code
***********************

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System.Data"
StackTrace:
at
System.Data.DataRowView.System.ComponentModel.IDat aErrorInfo.get_Item(String
colName)
at
System.Windows.Forms.DataGridView.DataGridViewData Connection.GetError(Int32
boundColumnIndex, Int32 columnIndex, Int32 rowIndex)
at System.Windows.Forms.DataGridViewCell.GetErrorText (Int32
rowIndex)
at
System.Windows.Forms.DataGridViewTextBoxCell.GetEr rorIconBounds(Graphics
graphics, DataGridViewCellStyle cellStyle, Int32 rowIndex)
at
System.Windows.Forms.DataGridViewCell.GetErrorIcon Bounds(Int32
rowIndex)
at
System.Windows.Forms.DataGridViewCell.UpdateCurren tMouseLocation(DataGridViewCellMouseEventArgs
e)
at
System.Windows.Forms.DataGridViewCell.OnMouseMoveI nternal(DataGridViewCellMouseEventArgs
e)
at
System.Windows.Forms.DataGridView.OnCellMouseMove( DataGridViewCellMouseEventArgs
e)
at
System.Windows.Forms.DataGridView.UpdateMouseEnter edCell(HitTestInfo
hti, MouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseMove(Mous eEventArgs
e)
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Packageer.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Apr 9 '06 #1
0 1724

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

Similar topics

1
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
2
by: Dante | last post by:
Has anyone ever successfully gotten a web deployed exe to have Drag Drop capabilities? I'm currently getting the message: An unhandled exception of type 'System.InvalidOperationException'...
7
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.