469,945 Members | 2,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

User control has no impact on parent control

My question concerns C# Windows Forms user controls.
I have created navigation user control. It gets the parent control's
CurrencyManager to its bindable property. In the control, any change in
the CurrencyManager position is displayed OK. But the problem is that
the position of the parent CurrencyManager stays intact (doesn't change
at all).
In methods, a reference parameter solves such problem, but I don't know
how to implement it with User control.
Any help will be appreciated.
Thanks,
David

Nov 17 '05 #1
2 2112
David,

You shouldn't need a reference parameter. The CurrencyManager isn't
what is being passed around, it is a reference that is being passed around.

Do you see the change in the parent control? You should see it in the
child control if you are indeed pointing to the same CurrencyManager.

Do you have a sample of code you can post which shows the problem?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David K." <ke*******@013.net> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
My question concerns C# Windows Forms user controls.
I have created navigation user control. It gets the parent control's
CurrencyManager to its bindable property. In the control, any change in
the CurrencyManager position is displayed OK. But the problem is that
the position of the parent CurrencyManager stays intact (doesn't change
at all).
In methods, a reference parameter solves such problem, but I don't know
how to implement it with User control.
Any help will be appreciated.
Thanks,
David

Nov 17 '05 #2
Hi Nicholas,

My User Control is a Panel with 4 Buttons and a Label.
Fere is my code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace UC_NavigationButton
{
/// <summary>
/// Navigation control. Consists of 4 buttons, lable and a panel.
/// </summary>
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnLast;
private System.Windows.Forms.Button btnNext;
private System.Windows.Forms.Button btnPrev;
private System.Windows.Forms.Button btnFirst;
private System.Windows.Forms.Label lblRecord;
private System.ComponentModel.Container components = null;
private CurrencyManager cm;
private System.Windows.Forms.Control control;

public UserControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.btnLast = new System.Windows.Forms.Button();
this.btnNext = new System.Windows.Forms.Button();
this.btnPrev = new System.Windows.Forms.Button();
this.btnFirst = new System.Windows.Forms.Button();
this.lblRecord = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(304, 40);
this.panel1.TabIndex = 0;
//
// btnLast
//
this.btnLast.Font = new System.Drawing.Font("Microsoft Sans Serif",
8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnLast.Location = new System.Drawing.Point(264, 8);
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(32, 23);
this.btnLast.TabIndex = 1;
this.btnLast.Text = ">|";
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// btnNext
//
this.btnNext.Font = new System.Drawing.Font("Microsoft Sans Serif",
8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnNext.Location = new System.Drawing.Point(224, 8);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(32, 23);
this.btnNext.TabIndex = 2;
this.btnNext.Text = ">";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// btnPrev
//
this.btnPrev.Font = new System.Drawing.Font("Microsoft Sans Serif",
8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnPrev.Location = new System.Drawing.Point(48, 8);
this.btnPrev.Name = "btnPrev";
this.btnPrev.Size = new System.Drawing.Size(32, 23);
this.btnPrev.TabIndex = 3;
this.btnPrev.Text = "<";
this.btnPrev.Click += new System.EventHandler(this.btnPrev_Click);
//
// btnFirst
//
this.btnFirst.Font = new System.Drawing.Font("Microsoft Sans Serif",
8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnFirst.Location = new System.Drawing.Point(8, 8);
this.btnFirst.Name = "btnFirst";
this.btnFirst.Size = new System.Drawing.Size(32, 23);
this.btnFirst.TabIndex = 4;
this.btnFirst.Text = "|<";
this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
//
// lblRecord
//
this.lblRecord.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D;
this.lblRecord.Location = new System.Drawing.Point(88, 8);
this.lblRecord.Name = "lblRecord";
this.lblRecord.Size = new System.Drawing.Size(128, 23);
this.lblRecord.TabIndex = 5;
this.lblRecord.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
// this.lblRecord.Paint += new
System.Windows.Forms.PaintEventHandler(this.lblRec ord_Paint);
//
// UserControl1
//
this.Controls.Add(this.lblRecord);
this.Controls.Add(this.btnFirst);
this.Controls.Add(this.btnPrev);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnLast);
this.Controls.Add(this.panel1);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(304, 40);
this.ResumeLayout(false);

}
#endregion

private void btnPrev_Click(object sender, System.EventArgs e)
{
if(cm.Position > 1)
{
cm.Position--;
lblRecord.Text = "Record " + cm.Position.ToString() + " of " +
(cm.Count - 1).ToString();
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
if(cm.Position < cm.Count - 1)
{
cm.Position++;
lblRecord.Text = "Record " + cm.Position.ToString() + " of " +
(cm.Count - 1).ToString();
}
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
cm.Position = 0;
lblRecord.Text = "Record " + cm.Position.ToString() + " of " +
(cm.Count - 1).ToString();
}
private void btnLast_Click(object sender, System.EventArgs e)
{
cm.Position = cm.Count;
lblRecord.Text = "Record " + cm.Position.ToString() + " of " +
(cm.Count - 1).ToString();
}
// Make this property bindable.
[System.ComponentModel.Bindable(true)]
public CurrencyManager ControlCurrencyManager
{
get
{
return cm;
}
set
{
cm = value;
}
}
// Make this property bindable.
[System.ComponentModel.Bindable(true)]
public System.Windows.Forms.Control ParentControl
{
get
{
return control;
}
set
{
control = value;
}
}

}
}

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ian | last post: by
5 posts views Thread by Steve Richter | last post: by
6 posts views Thread by Art | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.