|
-
November 16th, 2004, 03:41 AM
#1
A trouble with data binding in my control
I've create my own control - PageControl (derived from UserControl), which acts like TabControl but has no tabs. It's a collection of my class PageControlItem, which is derived from Panel and represents page itself.
So trouble is in the following situation. Let's assume that I have DataSet, DataView on my form, and TextBox on the page of PageControl. When I'm trying to bind TextBox to DataSet everything goes OK, but when I'm binding it to DataView an exception occures: Cannot bind to property or column <Column_Name> on DataSource.
I've tried that not only with TextBox, also even with PageControl and its page, which is PageControlItem. With PageControl itself everything is OK again, but fails with PageControlItem. That's why I think that the problem is in my code which adds a page to PageControl.
This is the code which is executed when the page is being added to PageControl:
Code:
page.Parent = this;
page.Dock = DockStyle.Fill;
if (Parent.SelectedPage != null)
{
Parent.SelectedPage._Active = false;
Parent.SelectedPage.Visible = false;
}
_Active = true;
Visible = true;
And this is what designer generetes itself in InitializeComponent
Code:
//
// pageControl1
//
this.pageControl1.Controls.Add(this.pageControlItem1);
this.pageControl1.Controls.Add(this.pageControlItem2);
this.pageControl1.Controls.Add(this.pageControlItem3);
this.pageControl1.Location = new System.Drawing.Point(72, 48);
this.pageControl1.Name = "pageControl1";
this.pageControl1.Pages.AddRange(new PageControl.PageControlItem[] {
this.pageControlItem1,
this.pageControlItem2,
this.pageControlItem3});
this.pageControl1.SelectedPageIndex = 1;
this.pageControl1.Size = new System.Drawing.Size(600, 232);
this.pageControl1.TabIndex = 0;
//
// pageControlItem1
//
this.pageControlItem1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pageControlItem1.Location = new System.Drawing.Point(0, 0);
this.pageControlItem1.Name = "pageControlItem1";
this.pageControlItem1.Size = new System.Drawing.Size(600, 232);
this.pageControlItem1.TabIndex = 0;
//
// pageControlItem2
//
// ((ISupportInitialize)dataView1).EndInit(); if you uncomment this and the next second line everything will work OK
this.pageControlItem2.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.dataView1, "id"));
// ((ISupportInitialize)dataView1).BeginInit();
this.pageControlItem2.Dock = System.Windows.Forms.DockStyle.Fill;
this.pageControlItem2.Location = new System.Drawing.Point(0, 0);
this.pageControlItem2.Name = "pageControlItem2";
this.pageControlItem2.Size = new System.Drawing.Size(600, 232);
this.pageControlItem2.TabIndex = 1;
//
// pageControlItem3
//
this.pageControlItem3.Dock = System.Windows.Forms.DockStyle.Fill;
this.pageControlItem3.Location = new System.Drawing.Point(0, 0);
this.pageControlItem3.Name = "pageControlItem3";
this.pageControlItem3.Size = new System.Drawing.Size(600, 232);
this.pageControlItem3.TabIndex = 2;
And the most interesting is that if I'm binding pageControlItem3 being the SelectedPage of PageControl everything works as is needed.
Any guesses please. What did I possibly miss?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|