Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing UserControl as Function/Method Parameter

13 views
Skip to first unread message

Jarppi

unread,
May 6, 2013, 9:10:22 AM5/6/13
to
Hi All,
I'm populating a tab control with tab pages dynamically and in turn, each tab page that is created has to have a specific user control added to it.

Now I've managed to do this, no problem, but I'm working on a function that I can call from each menu item I click, to do the job, instead of copying and pasting the same code over and over and over again, only to change one line. So this is what I've got so far:

...//START CODE
private void CreateTab(string TabName, ref XtraUserControl uiElement, Image tabIcon)
{
if (!CheckTab(TabName))
{
XtraTabPage x = new XtraTabPage();
x.Image = tabIcon;
x.Text = TabName;

x.Controls.Add(uiElement);
foreach (UserControl j in x.Controls)
{
j.Dock = DockStyle.Fill;
}

xtMain.TabPages.Add(x);
SelectTab(TabName);
}
else
{
SelectTab(TabName);
}
}
...//END CODE

The problem is that my code won't compile. The error is specific to the user control parameter I'm passing, it's getting a conversion error for some reason. I'm using DevExpress components, and yes the UserControl does inherit XtraUserControl.

I'm calling the method like this:

...//START CODE

CreateTab("POS", new Sales.POSUI(), Properties.Resources.sales_16);

...//END CODE

Any idea? Or am I trying to do something that cannot be done?

Regards
J
0 new messages