Private Sub CheckInOutUnitAddDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles CheckInOutUnitAddDataGridView.CellEndEdit
If e.ColumnIndex = 2 Then
Dim dt As DataTable = DirectCast(DirectCast(CheckInOutUnitAddDataGridView.DataSource, BindingSource).DataSource, DataSet).Tables(CheckInOutUnitAddDataGridView.DataMember)
If Convert.ToBoolean(dt.Rows(e.RowIndex)(e.ColumnIndex)) Then
Dim count As Integer = dt.[Select]("OrderSelectionFlag=1 and ProductUnitID=" & dt.Rows(e.RowIndex)(1).ToString()).Length
If count > 1 Then
MessageBox.Show("Error: You can not select this")
dt.Rows(e.RowIndex)(e.ColumnIndex) = False
End If
End If
End If
End Sub
Error Message:
System.InvalidCastException was unhandled
Message="Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataSet'."
Source="Transact"
StackTrace:
at Transact.CheckInOutForm.CheckInOutUnitAddDataGridView_CellEndEdit2(Object sender, DataGridViewCellEventArgs e) in C:\Path\CheckInOutForm.vb:line 247
at System.Windows.Forms.DataGridViewCellEventHandler.Invoke(Object sender, DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnCellContentClick(DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnCommonCellContentClick(Int32 columnIndex, Int32 rowIndex, Boolean doubleClick)
at System.Windows.Forms.DataGridViewCell.OnMouseUpInternal(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnCellMouseUp(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Transact.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.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: