all groups > dotnet windows forms databinding > september 2005 >
You're in the

dotnet windows forms databinding

group:

Databinding Error on Tab Control


Databinding Error on Tab Control Lynn
9/19/2005 2:55:04 PM
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)
RE: Databinding Error on Tab Control v-jetan NO[at]SPAM online.microsoft.com (
9/20/2005 12:00:00 AM
Hi Lynn,

Thanks for your post.

Sorry, but it seems that you did not provide the databinding information.
Based on the call stack, the problem should be caused by the databinding,
so the databinding information is critical. Can you show us which is the
datasource and you bind the datasouce to which control?

Also, there are many variables symbols in your project without any
explanation, which may cause much confusion for our understanding. I think
you may try to explain your program logic in a much simpler way, so that
the community members can understand your application logic from a large
point and reducing confusion.

Additionally, if you can narrow down the issue into a reproduce project, it
will be better. For example, you can reduce your project logic into a much
simpler scenario, then create a sample app. Yes, I see this is not easy,
however, this is the specialty of newsgroup support: without getting the
full project, the understanding for the program logic is very critical. So
a good explanation is critical. Thanks for your understanding.

At last, from the exception message, it seems that when you removed the
tabpage, the databinding pushed the UI data into the datatable(as a new
row), however, it causes "AssetInspectId" column in the new row to have
null value. However, the constraint on the "AssetInspectId" column did not
allow null value, so NoNullAllowedException is thrown out. To resolve
this, maybe you should give up the constraint for this column(by setting
DataColumn.AllowDBNull property to true), or provide a default value for
this column(by providing DataColumn.DefaultValue a default value). Or maybe
you have to modify the databinding logic to push a valid value to this
column

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button