Populate ComboBox when BO needs a datasource key


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Jason Seidell (06/29/2010)
Instead, I should alter the Business Object class and set the DatasourceKey so all instances of BusinessObjectA will use the datasource key and not have to intialize that property. Am I getting this right??


Yes.

Edhy Rijo

Jason Seidell
Jason Seidell
StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)
Group: Forum Members
Posts: 59, Visits: 180
Ok, I think I get what you are saying, and I think I see a possible setup configuration that I am missing.

Thus far I have set the datasource key in code after creating a business object or from the property box when adding an instance of a business object to a form, before I call any fill methods. 

For example:

Dim myBusinessObjectA as New ProcessingDB.BusinessObjectA

myBusinessObjectA.DatasourceKey = ProcessingDBDatasourceKey

myBusinessObjectA.FillAll()

Instead, I should alter the Business Object class and set the DatasourceKey so all instances of BusinessObjectA will use the datasource key and not have to intialize that property.  Am I getting this right??

Jason

Jason Seidell

Programmer/Analyst

Infinedi

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Jason.

In this case, your BusinessObjectB needs a DatasourceKey. As you say you are working with multiple databases, it looks like you are not setting this property at the BO. Nevertheless, you will need to do it, since you don't have the default "" datasourcekey set to any connection.

The combobox has a ListPopulating method where you can set the Parameters do the Fill method you created in the BusinessObjectB to fill the combobox items.

    Private Sub ComboBox1_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs)
        '-- send the desired datasourcekey
        e.Parameters(0).Value = whateverDataSourceKey
    End Sub

Then your fill method would be set to accept this parameter, being the DatasourceKey. Then, the first thing inside your fill method could be:

Me.DataSourceKey = MyDatasourceKeyParameter
Me.ReCreateDataLayer()

And then carry on with your fill method.

I haven't tried this yet, so let us know if it helps ltaer. Smile

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Check that the BO you selected to fill the combo has the correct data source key set. You do this by looking at the designer of that BO and check the DataSourceKey property. Likely you forgot to set it, and the default is "".



You don't ever need to set this when filling the combo. This is a BO setting, essentially enabling the BO to access data whenever needed.
Jason Seidell
Jason Seidell
StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)
Group: Forum Members
Posts: 59, Visits: 180
All I'm doing is to create a SF form, drop a combo box that binds to BusinessObjectA on a foreign key, and gets a descriptive name from BusinessObjectB. So I setup using the PopulationDataSourceSettings wizard from BusinessObjectB, but when it tries to populate I get an exception of 'Datasource [] does not exist'.  Because all the datasources are named because I connect to multiple databases, and cannot have a '' datasourcekey because of conflicts.  The PopulationDataSourceSettings does not point to a specific business object on the form, rather any business object in my library, and on other projects I have done you can populate a combobox from BusinessObjectB and only have a BusinessObjectA tied to the form.  So it would seem to me that on the backend SF makes a temp BO of whatever type I specific and runs the selected fill rountine, and I cannot define the DataSourceKey for that temp BO (if in case this is what is actually going on).

If I'm missing something here please feel free to fill me in....

Jason

Jason Seidell

Programmer/Analyst

Infinedi

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



I'm not quite sure what you are trying to do, but you don't have to set a data source key when setting up a combobox to be populated. The data source key is set on the BO itself. The combobox simply references the appropriate BO. The BO knows what data source to use, the combo just needs to know what BO.



When you setup a combobox's list populations settings, you supply:



- BO that is used to fill combo

- A fill method to load BO with data. There are a number of fill methods available by default (e.g. FillByPrimaryKey, FillByParent, FillByParentPrimaryKey, etc.), but typically you need to write a fill method within the BO. In the help file, under Application Framework|Business Layer|Fill Methods - Populating a Business Object section, there are a number topics that address how to fill a BO, including writing Fill methods. An example fill method might look like (this is within the code of a BO):



//-- In a BO. In this case, this might be in a CustomersBO.

Public Sub FillForLookup()

  Dim sqlBuilder As New StringBuilder(255)

  With sqlBuilder

    .AppendLine("Select cust_pk, cust_fname, cust_lname")

    .AppendLine("From Customers")

  End With



  Using cmd As New SqlCommand

    cmd.CommandText = sqlBuilder.ToString()

    Me.FillDataTable(cmd)

  End Using

End Sub




Notice that this fill method is specifically for use in lookup scenarios, like a combo. I'm not filling in all the data, just the data needed by the lookup (the combobox in this case). I'm assuming that the lookup will need to see the name and have the ID available for binding.



Once you have a Fill method in the BO, build the solution (so the new method can be picked up by the list population designer). Now, in the Method to Execute, you fill method should be listed (if not, you probably forgot to do the build).



The BO is setup with a datasourcekey. When the combobox is filled, it uses that key to make a connection to the data (via the DataSources collection that you setup in the SetDataSources of either AppMain.vb or Program.cs (depending on language)). The combobox then calls the set Method to Execute to load the BO, which then is used to load the combo. All of this happens behind the scenes based on how you setup the combobox to be filled.



I hope this help make some sense of what is happening. If you need more help, please don't hesitate to ask. You might want to include a more specific example too.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Jason,



Couple of thing to clarify...



Combobox does not use a data source key, the key is assigned to the business object which is the one responsible to get the data. With this in mind this is how I setup my comboboxes:

1.- I drop an instance of the BO which will be used in the combobox.

2.- In the combobox set the following properties as follow:

a: PopulateOnFormLoad = Manual

b: PopulationDatasourceSettings:

i: Method to Execute: CopyDataFrom(BuisnessLayerBase,BusinessCloneDataType)

3.- In the ListPopluating add code to copy the data from the form's bo to the combo

Private Sub cboCustomerName_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles cboCustomerName.ListPopulating

e.Parameters(0).Value = Me.BizClientesVFP1

e.Parameters(1).Value = MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable

End Sub


Now, you need to manually at some point fill the form's bo with the correct data, then just requery() the combobox.



Make sure you use the desired DataSourceKey in the BO class or instance in the form.


Edhy Rijo

Jason Seidell
Jason Seidell
StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)
Group: Forum Members
Posts: 59, Visits: 180
Well I at least found a good example on MSDN of how to populate a combo-box with items and get it to use the SelectedValue property for binding to the SF BO.   http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.valuemember.aspx

First I created a class to hold my items

Public Class ComboBoxItem(Of T)

Private _description As String

Private _value As T

''' <summary>

''' Initializes a new instance of the ComboBoxItem class.

''' </summary>

Public Sub New()

_description = String.Empty

End Sub

''' <summary>

''' Initializes a new instance of the ComboBoxItem class.

''' </summary>

Public Sub New(ByVal Description As String, ByVal Value As T)

Me.Description = Description

Me.Value = Value

End Sub

Public Overrides Function ToString() As String

Return String.Format("{0} ({1})", Description, Value)

End Function

Public Property Description() As String

Get

Return _description

End Get

Set(ByVal value As String)

_description = value

End Set

End Property

Public Property Value() As T

Get

Return _value

End Get

Set(ByVal value As T)

_value = value

End Set

End Property

End Class

Then on Form Load I run a function to populate

Dim elecPayers As New Infinedi.BO.Processing.Enrollment.ElectronicPayer_BO()

elecPayers.DataSourceKey = enrollmentDS.DatasourceKey

elecPayers.FillAll()

Dim elecPayerList As New ArrayList()

 

For i As Integer = 0 To elecPayers.Count - 1

elecPayers.MoveAbsolute(i)

elecPayerList.Add(New ComboBoxItem(Of Integer)(elecPayers.Name, elecPayers.ElectronicPayerID))

Next i

 

cmbElectronicPayerId.DataSource = elecPayerList

cmbElectronicPayerId.DisplayMember = "Description"

cmbElectronicPayerId.ValueMember = "Value"

So I'm at least to a point where I can move on and get it working, but I would still like to know why there isn't a property or field in the PopulationDataSourceSettings() to let me set the DatasourceKey instead of defaulting to a '' datasource key.

Jason Seidell

Programmer/Analyst

Infinedi

Jason Seidell
Jason Seidell
StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)StrataFrame Novice (103 reputation)
Group: Forum Members
Posts: 59, Visits: 180
I'm trying to figure out how to populate a combo box but I need to be able to set a DatasourceKey in the autopopulate settings and cannot.  When I try to manually populate the control I get data but as soon as you select an item the entire form locks and you cannot set focus to any other controls.  I'm completely lost as to why the combobox locks the form.

I'm frustrated that I cannot set the DatasourceKey for the population business object, and that I cannot find any examples for manually populating a business object.  All the documentation says to 'search for combobox population', and a vague reference to needing a datatable but no specifics for required fields.  Which seems odd since you populate a combobox with objects not datatables, or is there some interface the combobox items needs to support?

Jason

Jason Seidell

Programmer/Analyst

Infinedi

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