Strange behavior using FormODBase

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
wjstarck
Posts: 935
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Strange behavior using FormODBase

Post by wjstarck » Sun Jan 03, 2021 1:01 pm

I have a form that started behaving oddly in OD 20.4

This form has a listBox that contains exams from different dates and controls that are filled from the db depending on which exam date is clicked in the listBox.

The form works perfectly fine and has for years, but was recently converted over to inherit from FormODBase to take advantage of scaling.

However, now when I click in the window's title bar and then release, the listBox_SelectedIndexChanged event will fire and cause a crash. I would do this, for instance, when clicking on a title bar to drag a window somewhere else and then releasing. So it's happening on the MouseUp event. If I revert the inheritance to Form from FormODBase, everything runs as expected.

Here is the crash:

Code: Select all

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Anesthesia20.4
  StackTrace:
   at Anesthesia.FormAnestheticRecord.listAnesthetics_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\EASy20.4\Forms\FormAnestheticRecord.cs:line 1887
   at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
   at System.Windows.Forms.ListBox.ClearSelected()
   at OpenDental.LayoutManagerForms.LayoutChildren(Control control) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\opendental20.4\OpenDental\UI\BordersDpi\LayoutManagerForms.cs:line 606
   at OpenDental.LayoutManagerForms.LayoutChildren(Control control) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\opendental20.4\OpenDental\UI\BordersDpi\LayoutManagerForms.cs:line 654
   at OpenDental.LayoutManagerForms.LayoutFormBoundsAndFonts(FormODBase formODBase) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\opendental20.4\OpenDental\UI\BordersDpi\LayoutManagerForms.cs:line 491
   at OpenDental.FormODBase.OnResizeEnd(EventArgs e) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\opendental20.4\OpenDental\UI\BordersDpi\FormODBase.cs:line 381
   at OpenDental.FormODBase.PanelBorders_MouseUp(Object sender, MouseEventArgs e) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\opendental20.4\OpenDental\UI\BordersDpi\FormODBase.cs:line 1021
   at System.Windows.Forms.Control.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.ScrollableControl.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(IntPtr 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.RunDialog(Form form)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at System.Windows.Forms.Form.ShowDialog()
   at Anesthesia.FormOpenDentalA.menuItemAnestheticRecord_Click(Object sender, EventArgs e) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\EASy20.4\FormOpenDentalA.cs:line 616
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.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(IntPtr 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(Form mainForm)
   at OpenDental.ProgramEntry.Main(String[] args) in C:\Users\wjs\Desktop\ODVersions\opendental20.4\opendental20.4\OpenDental\Main Modules\ProgramEntry.cs:line 99
Line 1887 looks like so:

Code: Select all

		private void listAnesthetics_SelectedIndexChanged(object sender, EventArgs e) {
			if (!IsStartingUp) {
--------------------> anestheticRecordNum = AnestheticRecords.GetRecordNumByDate(listAnesthetics.SelectedItem.ToString()); 
				AnestheticData anesthData = AnesthDataCur;
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5739
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Strange behavior using FormODBase

Post by jordansparks » Sun Jan 03, 2021 3:14 pm

Yes, that's a known issue. Blame MS. If you change a font on a listbox, it clears the selected index. Who could've guessed? We need to change the font when we scale, so just handle it. When your selected index change event fires, just test for -1. We do automatically set the selected index back to what it was after we change the font. So plan for that event firing as well.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 935
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Strange behavior using FormODBase

Post by wjstarck » Sun Jan 03, 2021 5:04 pm

Thanks
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

Post Reply