473,608 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drag and Drop Unhandled NullReferenceEx ception

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_Mous eDown(ByVal sender As System.Object, ByVal
e As System.Windows. Forms.MouseEven tArgs) Handles dgProjects.Mous eDown
Dim hit As DataGridView.Hi tTestInfo = dgProjects.HitT est(e.X,
e.Y)
Dim dragSize As Size = SystemInformati on.DragSize
Dim pointTopLeft As Point = New Point(e.X - (dragSize.Width /
2), e.Y - (dragSize.Heigh t / 2))
dragRow = hit.RowIndex
dragBoxFromMous eDown = New Rectangle(point TopLeft, dragSize)
End Sub

Private Sub dgProjects_Mous eMove(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles dgProjects.Mous eMove
Try
If e.Button = Windows.Forms.M ouseButtons.Lef t Then
If Not dragBoxFromMous eDown.Contains( e.X, e.Y) Then
dgProjects.DoDr agDrop(dgProjec ts.Rows(dragRow ),
DragDropEffects .Move)
End If
End If
Catch
End Try
End Sub

Private Sub dgProjects_Mous eUp(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles dgProjects.Mous eUp
Try
dragBoxFromMous eDown = Rectangle.Empty
Catch
End Try
End Sub

Private Sub dgProjects_Drag Enter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles dgProjects.Drag Enter
Try
e.Effect = DragDropEffects .Move
Catch
End Try
End Sub

Private Sub dgProjects_Drag Drop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles dgProjects.Drag Drop
Try
Dim clientPoint As Point = dgProjects.Poin tToClient(New
Point(e.X, e.Y))
Dim hit As DataGridView.Hi tTestInfo =
dgProjects.HitT est(clientPoint .X, clientPoint.Y)
Dim myType As Type = GetType(DataGri dViewRow)

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

Dim DestRowOrderID As Integer = dgProjects("Ord erID",
hit.RowIndex).V alue
Dim movedRow As DataGridViewRow =
dgProjects.Rows (e.Data.GetData (myType).Index)
Dim DestRowAboveOrd erID As Integer
Dim OrderGap As Integer

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

dgProjects.EndE dit()
Me.Validate()

ProjectRegister BindingSource.S ort = "Active DESC, OrderID
DESC"
Try

ProjectRegister TableAdapter.Up date(dsProjects .ProjectRegiste r)
dsProjects.Acce ptChanges()
Catch ex As Exception
End Try

If OrderGap <= 2 Then
For Each dgvr As DataGridViewRow In dgProjects.Rows
dgvr.Cells("Ord erID").Value = dgvr.Index * 20
Next
ProjectRegister BindingSource.S ort = "Active DESC,
OrderID DESC"
Try

ProjectRegister TableAdapter.Up date(dsProjects .ProjectRegiste r)
dsProjects.Acce ptChanges()
Catch ex As Exception
End Try
End If
Catch
End Try
End Sub

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

System.NullRefe renceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System. Data"
StackTrace:
at
System.Data.Dat aRowView.System .ComponentModel .IDataErrorInfo .get_Item(Strin g
colName)
at
System.Windows. Forms.DataGridV iew.DataGridVie wDataConnection .GetError(Int32
boundColumnInde x, Int32 columnIndex, Int32 rowIndex)
at System.Windows. Forms.DataGridV iewCell.GetErro rText(Int32
rowIndex)
at
System.Windows. Forms.DataGridV iewTextBoxCell. GetErrorIconBou nds(Graphics
graphics, DataGridViewCel lStyle cellStyle, Int32 rowIndex)
at
System.Windows. Forms.DataGridV iewCell.GetErro rIconBounds(Int 32
rowIndex)
at
System.Windows. Forms.DataGridV iewCell.UpdateC urrentMouseLoca tion(DataGridVi ewCellMouseEven tArgs
e)
at
System.Windows. Forms.DataGridV iewCell.OnMouse MoveInternal(Da taGridViewCellM ouseEventArgs
e)
at
System.Windows. Forms.DataGridV iew.OnCellMouse Move(DataGridVi ewCellMouseEven tArgs
e)
at
System.Windows. Forms.DataGridV iew.UpdateMouse EnteredCell(Hit TestInfo
hti, MouseEventArgs e)
at System.Windows. Forms.DataGridV iew.OnMouseMove (MouseEventArgs
e)
at System.Windows. Forms.Control.W mMouseMove(Mess age& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.DataGridV iew.WndProc(Mes sage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext
context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Packageer.My.My Application.Mai n(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

Apr 9 '06 #1
0 1742

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

Similar topics

1
536
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 system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
0
2592
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 simutate it. Can anyone help? Thanks ************************** previous post: Message 1 in thread
2
4319
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 there? What about Drag/Drop; is there more than one way for the source to make data available Is it always OLE?
3
10399
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== using System; using System.Drawing; using System.Collections; using System.ComponentModel;
2
1407
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' occurred in mscorlib.dll Additional information: DragDrop registration failed. Any help would be greatly appreciated.
7
2675
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 server returned an error: (500) Internal Server Error." I found a post that suggested to catch the WebException to retrieve the actual HttpWebResponse object for more information. The response returned is shown below. At first I thought this was a...
6
3543
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 where the user can run on firefox/mozilla, what would be a good approach. 1. Should I overwrite the javascript code drag-and-drop to make it more browser independent. If I want to go this route, can anybody provide me a
3
10585
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
5
13762
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 drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented. I´ve also commented the whole code so you guys can easier understand it engine. What exactly we need when trying to make a column drag &...
0
8002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8496
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8475
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
8148
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
6816
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
6013
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
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1329
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.