Difference between user control and form


Author
Message
David Daragon
David Daragon
StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)
Group: Forum Members
Posts: 54, Visits: 249
Hi,

I'm still making tests.

I put a list view in a Micro Four User Control which is contained in a Micro Four Form and the time of loading is 2800 ms.

When I put directly the same list in a Micro Four Form, the time is about 450 ms.

What are the reasons of this difference ?

Best regards

David

Replies
David Daragon
David Daragon
StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)
Group: Forum Members
Posts: 54, Visits: 249
Hi

I succeed to load a listview in an user control with a designer. But I'm not sure you understand my problem.
I want to add an user control by code
UserControl _uc = new UserControl();

I wonder how to link a BO in the form and in the user control in the code and set the PopulationDataSourceSettings.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If I understand you correctly, you want to programatically add your user control (that contains a listview) to a form, then setup the listview to use data from a BO on the form. Assuming this is what you want to do, you have a few options:



- Expose the listview as a readonly property of the user control so you can setup it up in code. I.e. you'd use client code (the code in your form) something like:



UserControl _uc = new UserControl();

//Setup list population settings..

_uc.List.PopulationDataSourceSettings.MethodToExecute = "CopyDataFrom;BusinessLayer,BusinessCloneDataType";

// Add handler for list population (populateList would be the method on the form

// that handles this event)

_uc.List.ListPopulating += new ListPopulatingEventHandler(this.populateList);




- If you are always going to populate the list view from an external BO using CopyDataFrom, you'd be better off to just setup the listview in the user control that way, and add a BO property to your user control of type BusinessLayer. You'd then handle the ListPopulating event within the user control. The client code would then become:



UserControl _uc = new UserControl();

// Set BO

_uc.BusinessObject = this.MyLocalBO; //MyLocalBO being the one you want to load from




The code may not be entirely accurate, I just typed it in, but hopefully it gives you an idea of what you might want to do. BigGrin
David Daragon
David Daragon
StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)StrataFrame Novice (88 reputation)
Group: Forum Members
Posts: 54, Visits: 249
You're right Greg. I want to programatically add an user control in my form.

I set the properties by code but nothing happened. I may forgot something but why I don't know.

public Form1()
{

InitializeComponent();

_clientBO = new ClientBO();
_clientBO.ParentFormLoading +=
new MicroFour.StrataFrame.UI.IInitOnFormLoad.ParentFormLoadingEventHandler(_clientBO_ParentFormLoading);

_clientBO.ParentContainer = this;
_clientBO.SynchronizingObject =
this;

_ucClient = new ucClient();

this.PrimaryBusinessObject = _clientBO;
_BOTranslationItem1.DestinationBusinessObject = "_ucClient.clientBO1";
_BOTranslationItem1.SourceBusinessObject =
"Form1._clientBO";

_ucClient.BOTranslations.AddRange(new MicroFour.StrataFrame.UI.Windows.Forms.BusinessObjectTranslationItem[] {

_BOTranslationItem1});

_ucClient.Dock = System.Windows.Forms.DockStyle.Fill;

_ucClient.ParentContainer = this;
_ucClient.TranslationObject =
this;

this.Controls.Add(_ucClient);

}

void _clientBO_ParentFormLoading()
{
_clientBO.RetournerTousClients();
}


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
David,



I see a couple of things that don't make sense:



- Were are you calling Requery() on the listview in your user control?



- I'm thinking that _clientBO.RetournerTousClients(); is a fill method that fills the _clientBO with data. Are you thinking that this will somehow fill your listview? Even if the listview is configured to use the same type of BO as the local instance _clientBO, it won't use that instance. The listview creates its own instance.



If you'd like to use the data from _clientBO to fill the listview, then you need to configure the listview to use the CopyDataFrom method using the businesslayer overload. Then you must either pass in the appropriate parameters to the Requery() method OR handle the ListPopulating method and provide those parameters. In almost all cases it is better to handle the event. Hope this is starting to make sense.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
David Daragon - 17 Years Ago
Trent L. Taylor - 17 Years Ago
David Daragon - 17 Years Ago
David Daragon - 17 Years Ago
David Daragon - 17 Years Ago
                         Just one more thing, there is an error in my code. The line...
David Daragon - 17 Years Ago
                             David, First, I think that you are making this harder than you need...
Trent L. Taylor - 17 Years Ago
                                 Thanks for your help Trent, I follow your method and it's work. But...
David Daragon - 17 Years Ago
                                     Gotcha....yes, you can do this in code, but you will have to do it in...
Trent L. Taylor - 17 Years Ago
                                         In which OnLoad ? In the form or in the user control ?
David Daragon - 17 Years Ago
                                             Really either. It depends on what you are trying to accomplish with...
Trent L. Taylor - 17 Years Ago
                                                 Hi Trent, In fact, I want to use User Control to re use them in...
David Daragon - 17 Years Ago
                                                     [quote]What can I do ?[/quote] Well, let's go at it from this...
Trent L. Taylor - 17 Years Ago
                                                         Hello Trent, Here is my code. [codesnippet] public partial...
David Daragon - 17 Years Ago
                                                             I really think that something is missing. I don't think that the...
Trent L. Taylor - 17 Years Ago
                                                                 Hi Trent, I send you a sample project. I put the 2 examples. One with...
David Daragon - 17 Years Ago
                                                                     Hi Did you have the time to test my sample ? Regards, David
David Daragon - 17 Years Ago
                                                                         I will take a look at this soon, but we have just gotten back from...
Trent L. Taylor - 17 Years Ago
                                                                             No worry Trent I just want to know to organize my work. I will work...
David Daragon - 17 Years Ago
                                                                             no issue at my problem ?
David Daragon - 17 Years Ago
Dustin Taylor - 17 Years Ago
David Daragon - 17 Years Ago
                 It would be better with the attachment :D ;)
David Daragon - 17 Years Ago
Trent L. Taylor - 17 Years Ago
                         Hi I succeed to load a listview in an user control with a designer....
David Daragon - 17 Years Ago
                             If I understand you correctly, you want to programatically add your...
Greg McGuffey - 17 Years Ago
                                 You're right Greg. I want to programatically add an user control in my...
David Daragon - 17 Years Ago
                                     David,

I see a couple of things that don't make sense:...
Greg McGuffey - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search