StrataFrame Forum

Binding an Enhanced List at runtime

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

By Andria Jensen - 6/12/2006

I'm trying to use a generic form to maintain several different tables in the database.  They all use the same form, but just different data sources.  What is the best way to do this in code at run-time instead of setting it through the designer at design time?  I figure I need to set some properties of the PopulationDataSourceSettings, but what I'm doing hasn't been working.  Here's the code I've got so far to bind the grid, and maybe someone can tell me what I have missing.

Public Class frmSFTableBase
   Public Sub New(ByVal HdrBO As BusinessLayer, ByVal HdrValue As String) 
      Me
.BusinessObjects.Add(HdrBO)
     
Me.grdHdr.PopulationDataSourceSettings.BusinessObjectType = "BBS.Biz.BizTypeBO"      Me.grdHdr.PopulationDataSourceSettings.ValueMember = HdrValue
     
Me.grdHdr.PopulationDataSourceSettings.MethodToExecute = "FillDataTable()"
     
Me.grdHdr.PopulationDataSourceSettings.DisplayFieldNames.Add(HdrValue)
      Me
.grdHdr.PopulationDataSourceSettings.FormatColumns.Add("{0}", MicroFour.StrataFrame.UI.ListViewColumnPopulationType.FormattedString)
      Me
.InitializeComponent()

End Sub

   Private Sub grdHdr_ListPopulating(ByVal e As   MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles grdHdr.ListPopulating

       e.Parameters(0).Value =
"SELECT * FROM BizType"
 
End Sub

End Class

By StrataFrame Team - 6/12/2006

You can set the properties of the EnhancedList at runtime, but you would probably be best served to create PopulationDataSourceSettings at design-time and then copying the code from the InitializeComponent method.  You're missing a few things when you're configuring them at runtime.

The MethodToExecute is a semi-colon-separated list of the method name and parameters... in this case, it would be "FillDataTable;System.String".  When we use the same list and populate it with several different data sets, we will set the PopulationDataSourceSettings manually within the code.  Other than that, your ListPopulating method is correct, but you'll need to call the Requery() method whenever you want to repopulate the list.

By Andria Jensen - 6/12/2006

Ok, I now have this:

Me.grdHdr.PopulationDataSourceSettings.BusinessObjectType = "BBS.Biz." & HdrValue & "BO"
Me.grdHdr.PopulationDataSourceSettings.DisplayFieldNames.AddRange(New String() {HdrValue})
Me.grdHdr.PopulationDataSourceSettings.FormatColumns.Add("{0}", MicroFour.StrataFrame.UI.ListViewColumnPopulationType.FormattedString)
Me.grdHdr.PopulationDataSourceSettings.FormatString = "{0}"
Me.grdHdr.PopulationDataSourceSettings.MethodToExecute = "FillDataTable;System.String"
Me.grdHdr.PopulationDataSourceSettings.ValueMember = HdrValue

But on the first line it gives me an exception and the message on Me.grdHdr is "Object cannot be null".  It looks like for some reason my grid is Nothing, but I created it on the form at design time so what else do I need to do to have an instance of it?

By Andria Jensen - 6/12/2006

Oh, and my grid is actually the Enhanced List control from the DevX wrapper classes.  Forgot to say that I think.
By Andria Jensen - 6/12/2006

Ok, it looks like you have to populate a ListViewPopulationSettings object and then set it the listview property.  This now works for me:

PopSettings.BusinessObjectType = "BBS.Biz." & HdrValue & "BO"
PopSettings.DisplayFieldNames.Add(HdrValue)
PopSettings.FormatColumns.Add(
"{0}", MicroFour.StrataFrame.UI.ListViewColumnPopulationType.FormattedString)
PopSettings.FormatString =
"{0}"
PopSettings.MethodToExecute = "FillDataTable;System.String"
PopSettings.ValueMember = HdrValue
Me.grdHdr.PopulationDataSourceSettings = PopSettings

By Trent L. Taylor - 6/12/2006

Yes, this is what we normally do as well.  Glad you got going. 
By Geoff Hirst - 3/11/2008

Guys,

How do you set up MethodToExecute if there is no parameter for the method being called?

thanks

Geoff Hirst

By Trent L. Taylor - 3/11/2008

How do you set up MethodToExecute if there is no parameter for the method being called?

Is that a trick question? Smile  You just leave off the parameters:

Me.grdHdr.PopulationDataSourceSettings.MethodToExecute = "FillDataTable;"