Difference between user control and form


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.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.
David Daragon
David Daragon
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 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 (2.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 (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 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.

Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
OK, there are actually a lot of issues with your approach here and none are related to the BO translations.  Now keep in mind that the forum is not intended for training purposes, but I am going to briefly break down where your issues are:

  1. You need to ensure that your projects enforce invalid variable declarations, etc. at compile time.  You can turn some compiler errors off, and this is not the crux of the issue, but bottom line is that you want to see all errors during a compile...let nothing be ignored.
  2. You are not properly using the ListView.  First of all, on your user control, you have a ListView that has a PopulationDataSourceSettings set to call your ReturnClientList() (I am paraphrasing here on your method name).  This will never work.  A ListView creates an internal BO.  In your user control, you do not reference or load from the clientBO1 anywhere.  So obviously you are not going to be able to load from that BO.  In your PopulationDataSourceSettings you need to set the Method To Invoke to CopyDataFrom, the you will handle the ListPopulating event to provide the clientBO1 there so that the instance you are trying to translate will appear.  There are a lot of samples on the forum as well as in the install of SF showing how to poipulate a ListView this way...including many examples in the StrataFlix sample.  Please refer to these samples to learn how to populate a ListView this way.
  3. Once you work through these problems, you will need to override the OnLoad method instead of handling the event (though you can handle the event, overriding the OnLoad gives you the control to place your code before or after the base logic...just good .NET standards).  When you setup a BO translation, all of this will be done within the OnLoad of the form and the controls...so you will want to place your logic there.  Now once the BO is translated....YOU WILL HAVE to requery the ListView in order to get the updated contents of the translated BO into the ListView.

    lstClients.Requery()

That should be enough to get you going down the right path. Smile

David Daragon
David Daragon
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 54, Visits: 249
It would be better with the attachment BigGrin Wink
Attachments
ProjetSFUserControl.zip (148 views, 778.00 KB)
David Daragon
David Daragon
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 54, Visits: 249
Hi Dustin,

Here is a new sample without Infragistics references.
In my table, I have 4 columns CodeClient, Nom, CodePostal and Adresse as you can see in my BO.designer.cs.

I don't succeed to load my list when I create manually my uc in my form.
And I don't know why.

Hope this sample will work on your computer.

Regards,

David

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (488 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
Hi David!

Could you re-post that sample with the infragistic references and toolstrips removed? We don't have the version of infragistics you are using, so we can't build the project as is.

Thanks!

David Daragon
David Daragon
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 54, Visits: 249
no issue at my problem ?
David Daragon
David Daragon
StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)StrataFrame Novice (54 reputation)
Group: Forum Members
Posts: 54, Visits: 249
No worry Trent I just want to know to organize my work.

I will work with Strataframe for many years so I have time BigGrin

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search