StrataFrame Forum

How Can I Populate my ListView from the Results of a Browse Dialog

http://forum.strataframe.net/Topic19980.aspx

By Marcia G Akins - 10/9/2008

The title says it all. Is there a simple way to let the browse dialog populate my listview?

Thanks!

By Greg McGuffey - 10/9/2008

I'm not super familiar with the BrowseDialog, but I'm guessing you'd drop a BO of the appropriate type on the form, drop a browsedialog on the form, setup the browse dialog to populate that BO when the user selects something, then setup the listview to CopyDataFrom that BO. Finally, handle the BO's CurrentTableRefilled event and requery the listview.



Hope that heads you in the right direction (or is so wrong somebody smarter will quickly correct me Pinch )


By Marcia G Akins - 10/9/2008

Greg McGuffey (10/09/2008)
I'm not super familiar with the BrowseDialog, but I'm guessing you'd drop a BO of the appropriate type on the form, drop a browsedialog on the form, setup the browse dialog to populate that BO when the user selects something, then setup the listview to CopyDataFrom that BO. Finally, handle the BO's CurrentTableRefilled event and requery the listview.

Hope that heads you in the right direction (or is so wrong somebody smarter will quickly correct me Pinch )

The browse dialog is working just fine. I have the ListView set up as bound to the same BO that the browse dialog is populating. But listview does not get populated. The Requery() method wants to call a method on the BO to populate it but that BO has already been poulated by the browse dialog Rolleyes  I just want to tell the listview to go populate itself from the BO that was populated by the browse dialog.

Thanks for trying to help.

By Marcia G Akins - 10/9/2008

Hi Greg.

Greg McGuffey (10/09/2008)

Hope that heads you in the right direction (or is so wrong somebody smarter will quickly correct me Pinch )

Just as an FYI, the only reason that I was going to use the listview was that it looked like it might be easier to put an image in the first column. Instead, I went to a DataGridView and added an unbound image column. I put this code in the BrowseDialogClosed() event handler and it worked just fine:

// Set up the icons for the traffic lights

if (!boViewTracking.IsEmpty)

{

foreach (DataGridViewRow loRow in grdViewTracking.Rows)

{

int tlINT = Convert.ToInt32(loRow.Cells["TL"].Value.ToString());

loRow.Cells["TrafficLight"].Value = imgViewTracking.Images[tlINT];

}

}

By Greg McGuffey - 10/9/2008

You need to set the MethodToExecute to CopyDataFrom, use the business layer version.



Setup handler on CurrentTableRefilled on the BO in question, call requery of listview.



Add handler for the listview's ListPopulating and set the two params needed for CopyDataFrom, the first is the BO the second is an enum indicating how to fill listview from bo.



Of course, if the datagridview is working, you might not want to mess with it, but it is very easy to populate a listview from a BO...once you figure it out! BigGrin
By Marcia G Akins - 10/10/2008

Greg McGuffey (10/09/2008)
Of course, if the datagridview is working, you might not want to mess with it, but it is very easy to populate a listview from a BO...once you figure it out! BigGrin

My philosophy is "if it ain't broke, don't fix it Tongue

But I will keep your exellent advice handy for the future.

Thanks again.

By Trent L. Taylor - 10/10/2008

The ListView is a lighter control and geared for this very thing.  The method that you want to use is the CopyDataFrom (as mentioned earlier).  A ListView (or any SF list for that matter) does not keep an instance of the BO that you specify in the PopulateDataSourceSettings property, but rather uses that and the method that you specify to populate the list and then disposes of that object.  So in this case, you wouldhave a BO on the form that is the "real" BO that you populate.  Then in the ListView you will call the CopyDataFrom method.  This same BO would be the BOToPopulate on the BrowseDialog which gets populated on the way back from the Browse.  Then finally, the ListPopulating event of the ListView would be handled to supply the parms to the CopyDataFrom method:

e.Parameters(0).Value = MyBOInstance
e.Paramteres(1).Value = BusinessObjectCloneType.ClearAndFillFromDefaultView
By Marcia G Akins - 10/11/2008

Trent L. Taylor (10/10/2008)
The ListView is a lighter control and geared for this very thing.  The method that you want to use is the CopyDataFrom (as mentioned earlier).  A ListView (or any SF list for that matter) does not keep an instance of the BO that you specify in the PopulateDataSourceSettings property, but rather uses that and the method that you specify to populate the list and then disposes of that object.  So in this case, you wouldhave a BO on the form that is the "real" BO that you populate.  Then in the ListView you will call the CopyDataFrom method.  This same BO would be the BOToPopulate on the BrowseDialog which gets populated on the way back from the Browse.  Then finally, the ListPopulating event of the ListView would be handled to supply the parms to the CopyDataFrom method:

e.Parameters(0).Value = MyBOInstance
e.Paramteres(1).Value = BusinessObjectCloneType.ClearAndFillFromDefaultView

Hi Trent.

 

Thanks so much for the detailed explanation. That makes everything crystal clear. I will definitely be using the listview in the future

By Trent L. Taylor - 10/13/2008

Sounds good Smile