dotnet windows forms databinding:
I have several controls on a tab control contained in a User Control (which I
call the tabPanel).
sample code:
public class TabPanel: System.Windows.Forms.UserControl
{
private System.Windows.Forms.TabControl tabControl1;
private NAMISM.WinUI.TemplateUI.TInspectionScheduleBaseUC
tInspectionScheduleBaseUC1;
private NAMISM.WinUI.TemplateUI.TRemoveInstallBaseUC
tRemoveInstallBaseUC1;
private NAMISM.WinUI.TemplateUI.TWorkCardsBaseUC tWorkCardsBaseUC1;
private NAMISM.BusinessClasses.TemplateDS dsTemplate;
private NAMISM.WinUI.TemplateUI.BaseControls.TAssetInspectionBaseUC
tAssetInspectionBaseUC1;
private NAMISM.WinUI.TemplateUI.TWorkCentersBaseUC
tWorkCentersBaseUC1;
}
I have logic to remove certain tabs from the tabControl depending on the
situation. When I try to remove a certain TabPage, I get this call stack
which is attached. I am also sending you the my method that handles the tab
removal.
Method:
public void search_TemplateSelected(Guid tmpltId)
{
if(tmpltId==Guid.Empty)
{
dsTemplate.Clear();
template=new Template(dsTemplate, Template.TemplateTypeCode.IN);
this.ParentForm.Text="New Scheduled Maintenance";
newTemplate=true;
this.mnemonicTabControl1.TabPages.Remove
(this.tabInspectionSchedule);
this.mnemonicTabControl1.TabPages.Remove(this.tabWorkCenter);
this.mnemonicTabControl1.TabPages.Remove(this.tabRemoveInstall);
this.mnemonicTabControl1.TabPages.Remove(this.tabWorkCard);
//This is the line of code that is erroring out on.
this.mnemonicTabControl1.TabPages.Remove(this.tabAssetInspection);
}
AssetInspectId is referring to a key field in my Asset table. But I am not
adding any
asset records in the action I am taking so the key field shouldn't even be
required.
Call Stack:
System.Data.NoNullAllowedException: Column 'AssetInspectId' does not allow
nulls.
at System.Data.DataView.FinishAddNew(Int32 currentIndex, Boolean success)
at System.Data.DataRowView.EndEdit()
at System.Windows.Forms.CurrencyManager.EndCurrentEdit()
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32
newPosition, Boolean validating, Boolean endCurrentEdit, Boolean
firePositionChange, Boolean pullData)
at System.Windows.Forms.CurrencyManager.UpdateIsBinding(Boolean force)
at System.Windows.Forms.CurrencyManager.UpdateIsBinding()
at System.Windows.Forms.CurrencyManager.SuspendBinding()
at System.Windows.Forms.CurrencyManager.FindGoodRow()
at System.Windows.Forms.CurrencyManager.CurrencyManager_PushData()
at System.Windows.Forms.CurrencyManager.OnCurrentChanged(EventArgs e)
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32
newPosition, Boolean validating, Boolean endCurrentEdit, Boolean
firePositionChange, Boolean pullData)
at System.Windows.Forms.CurrencyManager.AddNew()
at
System.Windows.Forms.RelatedCurrencyManager.ParentManager_CurrentChanged(Object sender, EventArgs e)
at System.Windows.Forms.RelatedCurrencyManager..ctor(BindingManagerBase
parentManager, String dataField)
at System.Windows.Forms.BindingContext.EnsureListManager(Object
dataSource, String dataMember)
at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext
newBindingContext, Binding binding)
at System.Windows.Forms.Control.UpdateBindings()
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.set_BindingContext(BindingContext value)
at
System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value)
at System.Windows.Forms.ContainerControl.get_BindingContext()
at System.Windows.Forms.Control.get_BindingContext()
at System.Windows.Forms.Control.get_BindingContext()
at System.Windows.Forms.DataGrid.Set_ListManager(Object newDataSource,
String newDataMember, Boolean force, Boolean forceColumnCreation)
at System.Windows.Forms.DataGrid.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.AssignParent(Control value)
at System.Windows.Forms.TabPage.AssignParent(Control value)
at System.Windows.Forms.ControlCollection.Remove(Control value)
at System.Windows.Forms.ControlCollection.Remove(Control value)
at System.Windows.Forms.TabPageCollection.Remove(TabPage value)
at
NAMISM.WinUI.TemplateUI.ScheduledMaintenance.SMTabPanel.search_TemplateSelected(Guid
tmpltId) in
c:\namism\winui\templateui\scheduledmaintenance\smtabpanel.cs:line 277
at
NAMISM.WinUI.TemplateUI.ScheduledMaintenance.SMForm.smSearchUC1_TemplateSelected(Object
sender, TemplateSelectedEventArgs args) in
c:\namism\winui\templateui\scheduledmaintenance\smform.cs:line 85
at NAMISM.WinUI.TemplateUI.BaseControls.TSearchBaseUC.btnAdd_Click(Object
sender, EventArgs e) in
c:\namism\winui\templateui\basecontrols\tsearchbaseuc.cs:line 291
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.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.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)