Access ComboBox internal data values


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
When using a ComboBox to select a lookup value, sometimes, you need to update more than one field in the form with values from the lookup.

Is there a way to access the values of the data in the Internal Combobox BO? or should we just use the PK field returned by the BindingField to look for the data again manually?

Edhy Rijo

Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
If the values you want to update are listed in the combobox, you should be able to access them through the combobox's Items collection. SelectedIndex will give you a pointer to the current item in the list.
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
Thanks Aaron,

I will try that.  I know i can create an Escalar method to get the value, but since the data is already in the combo, I don't want to do another trip to the data to get the same value.

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Another idea might be to use a form level BO that would hold the data needed to both fill the combo and to also provide the values for your other needs. You'd then fill the BO at the appropriate time and use CopyDataFrom method to fill the combo. This would allow you to put only the data needed in the combo for display but still have any data required (in the BO) for other uses. When the user selects a value, you'd just SeekToPrimaryKey to get the other values.



If I'm remembering this correctly, if the combo is filled via a BO method, then the items are DataRowView objects, with just two columns, display and value. You could probably figure out how to parse a multi-column combo, but seems like a lot of work when you could just be using a single BO to fill the combo and get the other values you need. In any case, this is what I've done in similar situations.



Hope that helps!
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 Greg,

Thanks, it does make sense, even though it would be nice to have access to the internal BO used by the combobox to get other columns values.

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If I recall correctly, that BO is created and destroyed during the fill. It isn't persisted at all. However, that is the beauty of the CopyDataFrom method, when you need to persist the data for other reasons! BigGrin
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
Greg McGuffey (09/19/2008)
If I recall correctly, that BO is created and destroyed during the fill. It isn't persisted at all. However, that is the beauty of the CopyDataFrom method, when you need to persist the data for other reasons! BigGrin

Hi Greg,

I finally had the chance to play with this, even though I have done this a lot of time with the listviews and like you said, it does work nicely, but it would do a very good enhancement to get access to the internal combobox BO. 

Anyway here is the code I am using from the 2 comboboxes to illustrate this functionality:

Private Sub cboItemType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboItemType.SelectedIndexChanged

     '-- Filter the cboItemName combobox data with the following parameters:

     ' Pass the PrimaryBO EditingState to filter out Active records if needed.

     ' The name of the Inactive Status field

     ' The ItemType value

     ' And the Appliance used.

     Me.BizItems_Lookup.Clear()

     Me.BizItems_Lookup.FillByActiveRecords(Me.bizSC_AppliancesItems1.EditingState, "ItemIsInactive", Me.bizSC_AppliancesItems1.ItemType, Me.BizSC_Appliances1.FK_Appliances)

     Me.cboItemName.Requery()

End Sub

 

Private Sub cboItemName_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles cboItemName.ListPopulating

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

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

End Sub

 

Private Sub cboItemName_DropDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboItemName.DropDown

     If bizSC_AppliancesItems1.Count > 0 Then

          Me.cboItemName.Requery()

     Else

          Me.cboItemName.Items.Clear()

     End If

End Sub

 

Private Sub cboItemName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboItemName.SelectedIndexChanged

     If Me.BizItems_Lookup.Count > 0 Then

          If Me.BizItems_Lookup.SeekToPrimaryKey(Me.bizSC_AppliancesItems1.FK_Items) Then

               Me.bizSC_AppliancesItems1.ItemPrice = Me.BizItems_Lookup.ItemPrice

          End If

     End If

End Sub



Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
You don't need access to the internal BO.  The internal BO is dead and gone once the combo is loaded.  But you have everything that you need right there in the data source.  When the BO is created and comes back, it is just executing the fill, using the parms specified, and the settings a DataTable to the DataSource of the combo.  So if you want to get to the datatable, just do this:

CType(MyCombo.DataSource, DataTable).Item("MyField")

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
Trent L. Taylor (09/22/2008)
You don't need access to the internal BO.  The internal BO is dead and gone once the combo is loaded.  But you have everything that you need right there in the data source.  When the BO is created and comes back, it is just executing the fill, using the parms specified, and the settings a DataTable to the DataSource of the combo.  So if you want to get to the datatable, just do this:

CType(MyCombo.DataSource, DataTable).Item("MyField")

Hi Trent,

Thanks for the info, but when testing your code above, I got an error that there is not Item property.  I have tried several ways to get access to any of the field values in the combo, but none worked.

Could you  please post the correct syntax to reference the combo field values?

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Sorry I was going quickly and didn't totally flesh out the properties.  It is just a data table so it would look like this:

CType(MyCombo.DataSource, DataTable).Rows(MyCombo.SelectedIndex).Items("MyField")

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