472,357 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,357 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 1664

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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.