StrataFrame Forum

Accessing additional combobox columns...

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

By StarkMike - 5/9/2006

I've noticed that when I'm setting up a combobox to be filled using a BO that I only have two columns to work with. The value column and the display column. Obviously the value column contains the ID and the display column can be a single field or a combination field. IE {1} or {1}{2}. I'm assuming I cant add any more columns to the combo box to hold related information about the items in the combo box.



If I am able to add more columns could you please instruct how to do so and then tell me how to access the information in these extra columns.



OR How would I query the datatable in the BO that contains the extra data. Keep in mind I'm piggybacking on a BO. Which is to say I'm executing Stored procedures to return records to fill combo boxes with.
By StrataFrame Team - 5/9/2006

No, the ComboBox is not sophisticated enough to store a tag like the ListView, so you can only store the information in either the display or the value column.  If necessary, you can call your stored procedure on a business object on the form (not the one dynamically created for the ComboBox) and use the CopyDataFrom method to copy data into the dynamicly created business object.  Then you would still have the business object on the form with all of the information necessary and you could Seek() to the record you need off the value in the ValueMember of the ComboBox.  Other than that, you would need some sort of complex drop down list with a custom control (like you would find in a 3rd party control suite).
By StarkMike - 5/10/2006

Ok. So now I'm going to use a DevExpress LookUpEdit. I'm assuming I can't do the piggyback thing with the lookupedit. Right? Is there another way or do I need to create a dataadapter and a dataset to fill the lookupedit?
By StrataFrame Team - 5/10/2006

On a LookupEdit, you can set a business object as the DataSource.  Just remember to set the IsListSource property to True on the business object before you set it as the DataSource.  Then, yes, you will still be able to piggy back off of a business object.
By StarkMike - 5/10/2006

On the LookUpEdit I have set the datasource to the BO. I have set the DisplayMember and ValueMember to "hidden" fields (by hidden I mean columns from the Stored Procedure I'm going to use to fill the combobox). And I have the columns set the same.



I discovered that I have to call the method of the BO that executes the Stored Procedure before it will fill the LookUpEdit. When I do that, though, I havent filled the BO with its Primary data, so something funky happens to the grid I have bound to the BO. I see a number of blank rows that correlates to the number of items in the combobox I've filled using the piggyback method.



Of course once I fill the BO with its primary data the grid fixes itself and displays the BO data correctly. Just wondering if this is something you guys need to know about as far as a "bug".
By StrataFrame Team - 5/10/2006

It's not really a bug... the DevExpress control is building its column list at design-time, and the columns on the business object change at runtime, so you just need to call Me.LookUpEdit1.Properties.PopulateColumns() to rebuild the column list off the data that's actually in the business object (where "LookUpEdit1" is the name of your LookUpEdit control).  Then you should be good to go.
By StarkMike - 5/10/2006

After I said all that I ran into a problem. Tongue



When i filled the BO with its primary data it erased the data in my combobox.
By StrataFrame Team - 5/10/2006

Yes, since the LookUpEdit is not one of our controls, it's not dynamically creating an instance of the business object on the back end, but actually using the business object that you're setting as the data source.  You'll need two different business objects on the form; one to be the source of the LookUpEdit, and one to be the primary business object you're working with.
By StarkMike - 5/11/2006

combobox.SelectedText isnt returning the value shown in the combo box after the selection. SelectedValue works ok though. Am I doing something wrong? I'm using the SF combobox which I assume inherits the windows one.
By StrataFrame Team - 5/11/2006

Yeah, the .NET ComboBox has some issues with the SelectedText property not always returning what's selected.  Try the Text property as well.
By StarkMike - 9/27/2006

I've noticed that when I'm setting up a combobox to be filled using a BO that I only have two columns to work with. The value column and the display column. Obviously the value column contains the ID and the display column can be a single field or a combination field. IE {1} or {1}{2}. I'm assuming I cant add any more columns to the combo box to hold related information about the items in the combo box.

If I am able to add more columns could you please instruct how to do so and then tell me how to access the information in these extra columns.

OR How would I query the datatable in the BO that contains the extra data. Keep in mind I'm piggybacking on a BO. Which is to say I'm executing Stored procedures to return records to fill combo boxes with.


This is an old post from May... I just wanted to see if this functionality has been added yet.

Thanks
By StarkMike - 9/27/2006

OR if I know how to do this with a DevExpress control that will still work on the inherited controls, right?
By StrataFrame Team - 9/27/2006

You cannot get more information from a combo box because the DataTable that is created for the combo box only contains the two columns that are the display member and the value member... Ermm
By StarkMike - 9/27/2006

Ok. Thanks. I won't ask again. Wink
By StrataFrame Team - 9/27/2006

You can, however, use a BusinessBindingSource wrapped around the business object and use it as your DataSource on the combo box (forgoing the PopulationDataSourceSettings) and only set the DisplayMember.  Then, when you access the SelectedValue, it will return an instance of the business object you used to populate the list, and you will have access to all of your properties on the business object.  The downside is that you can only select one field as the DisplayMember (you cannot concatenate more than one of them together), so you will have to concatenate the fields on SQL Server or somewhere else.
By StarkMike - 9/27/2006

Could you provide some code to get me started on that idea?
By Trent L. Taylor - 9/27/2006

This is actually done through the designer.  Just drop a BindingBusinessSource control on the form, choose the business object to wrap on the BusinessBindingSource.  Once this is done, go to your combo box and select the DataSource property and select the BusinessBindingSource.  Then go to the DisplayMember property and ValueMember properties and select the appropriate fields.
By StarkMike - 9/27/2006

Here is my scenario... I'm not going to use a DevExpress combobox (not an inherited one) and I'm going to bind it to a BBS which is bound to a BO. Now because the datatable in the BO has more columns than the combobox I need to be able to access those columns based on the value member i selected in the combobox. How can I do this?



I hope I have been clear... this binding source stuff has kind of thrown me and some of my code for a loop.
By Trent L. Taylor - 9/27/2006

In my previous post, I mentioned the ValueMember property.  Whatever field you associate with the property is what will be used to provide the value when referencing the SelectedValue property.  Does this make sense?
By StarkMike - 9/27/2006

Yes I understand what you are saying. You're talking about basic data binding with the combobox. Let me try to explain my question again.



Lets say in the datatable in my BO I have these fields:

EmployeeID, EmployeeName, EmployeeState



Here is how I set the properties for my combo box.

Value member: EmployeeID

Display member: EmployeeName



I understand that when I click on an item in the combobox that the SelectedValue gets set to whatever value is in EmployeeID.



However, how do I take the value that is in SelectedValue and "query" the BO to find the associated value in EmployeeState?
By StrataFrame Team - 9/28/2006

What you need to do, Mike, is only set the DisplayMember on the combo box.  When you only set the display member, and leave the ValueMember blank, the combobox's SelectedValue property will return an instance of the business object that was use to populate the combo box.  So, say this is the scenario:

1) you have MyBO dropped on the form
2) you have MyBBS (BusinessBindingSource) dropped on the form
3) you have MyBBS.BusinessObject set to MyBO
4) you have ComboBox1 dropped on the form and the DataSource property set to MyBBS
5) you have ComboBox1.DisplayMember set to "EmployeeName" and the ValueMember property left blank

When you run, the combo box will fill with the EmployeeName for every record in the business object.  When you access the ComboBox1.SelectedValue property, you will receive an instance of the MyBO class (an actual business object), on which, you can access all of the other columns within the business object (no just EmployeeID).