By Marcia G Akins - 9/6/2008
So, is there a way to so this in C#?
|
By William John Tello - 9/9/2008
Why would you disable individual items in a combobox (or a drop down list box for that matter)? I've never used Visual FoxPro or FoxPro for that matter, but that concept seems very much Window's application non-standard to me.In preference, why would you not just exlude any items that you would desire to be disabled within the combo box in the first place (meaning to not include them in the list of items which appear in the combobox)?
|
By Marcia G Akins - 9/9/2008
William John Tello (09/09/2008)
Why would you disable individual items in a combobox (or a drop down list box for that matter)? I've never used Visual FoxPro or FoxPro for that matter, but that concept seems very much Window's application non-standard to me. In preference, why would you not just exlude any items that you would desire to be disabled within the combo box in the first place (meaning to not include them in the list of items which appear in the combobox)? The reason is simple. All of my lookup detail items have an Active flag. Most of the businesses that I have written apps for, sometime make one or more lookup items inactive over time as their business requirements change. So, since the foreign key to the lookup is stored in the record (for example, customer_type_id would be stored in the customer record, telephone_type_id stored in the telephone record and so on). Obviously, when viewing a customer that has a type that was made inactive, I want the data to show up in the drop down list, but I do not want the users to be able to select inactive items for any new data that they are adding.
|
By Edhy Rijo - 9/9/2008
Marcia G Akins (09/09/2008)
The reason is simple. All of my lookup detail items have an Active flag. Most of the businesses that I have written apps for, sometime make one or more lookup items inactive over time as their business requirements change. So, since the foreign key to the lookup is stored in the record (for example, customer_type_id would be stored in the customer record, telephone_type_id stored in the telephone record and so on). Obviously, when viewing a customer that has a type that was made inactive, I want the data to show up in the drop down list, but I do not want the users to be able to select inactive items for any new data that they are adding. You won't believe this, but yesterday I was faced with the same situation and this is what I did: - Based on the main BO.EditingState I call a method in the LookupBO to either retall all records or just the Active records.
- Add a LookupBO to the form, this will be the source for the combobox internal BO.
- I setup the following properties for the combobox:
- PopulateOnFormLoad = Manual
- PopulationDataSourceSettings: CopyDataFrom(BusinessLayerBase,BusinessCloneDataType)
- Then add code to the combo ListPopulating event:
Private Sub cboCallAssignedTo_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles cboCallAssignedTo.ListPopulating '-- First parameter should be the Lookup BO e.Parameters(0).Value = Me.BizEmployees_LookUp '-- The second parameter expects the copy type e.Parameters(1).Value = MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable End Sub - Then add a method to the form that will be used to pump the correct data for the combo:
''' <summary>''' When adding a record will filter the data with Active employees''' when browsing created records will show all employees, even inactives''' that may have been selected before.''' </summary>''' <remarks></remarks>Private Sub SetEmployeeComboData() '-- Fill the cboCallAssignedTo combobox data If Me.BizServiceCalls1.EditingState = BusinessEditingState.Adding Then '-- Get only Active employees Me.BizEmployees_LookUp.FillActiveEmployeesOnly() Else '-- Get all employees Me.BizEmployees_LookUp.FillAllRecords() End If '-- Make sure the combo is requeried to show the correct data. Me .cboCallAssignedTo.Requery()End Sub
Then just add code to call your method when adding and after saving. This may not be the best way of doing this, but so far it works fine, when adding it will show only active records, when editing or browing will show all records.
|
By Marcia G Akins - 9/9/2008
Edhy Rijo (09/09/2008)
- Based on the main BO.EditingState I call a method in the LookupBO to either retall all records or just the Active records.
- Add a LookupBO to the form, this will be the source for the combobox internal BO.
- I setup the following properties for the combobox:
- PopulateOnFormLoad = Manual
- PopulationDataSourceSettings: CopyDataFrom(BusinessLayerBase,BusinessCloneDataType)
- Then add code to the combo ListPopulating event:
- Then add a method to the form that will be used to pump the correct data for the combo:
Then just add code to call your method when adding and after saving. This may not be the best way of doing this, but so far it works fine, when adding it will show only active records, when editing or browing will show all records. Thanks for the code. I suppose that I can add some code in the event handler for BeforeSave the check if they are trying to select an inactive item if they are in edit mode. Or is there a better place to check?
|
By Edhy Rijo - 9/9/2008
Marcia, Thanks for the code. I suppose that I can add some code in the event handler for BeforeSave the check if they are trying to select an inactive item if they are in edit mode. Or is there a better place to check? Yes you can do that and since you have a LookupBO instance in the form, this will have all the data in the combo and you can navigate that BO to locate the one selected in the combobox. Also if you prefer to handle this at the BO level, you can turn on the BO's Property Accessing/Changing/Changed events, and then trap the changes there:
|
By Greg McGuffey - 9/9/2008
Marcia & Edhy,
I got to thinking about this and ended up doing a little sample app to see if what I was thinking would work. Using this along with some of the ideas Edhy has provided might end up with a sweet solution.
Basically, I broke the issue into two parts:
1. Modify the display if items based on their status (active/inactive)
2. Only allow selection based on status.
The key to 1. is to setup the combo to be owner drawn, then draw the items based on status.
The key to 2. is to check the items selected in the SelectedIndexChanged property (or it might work better to use the property events Edhy mentioned) and if the item isn't active, chance the selection. I used an internal property to track the last item that was successfully selected to get this done. Note that this worked best if the combo had a top most item setup.
I personally like the idea of removing items during edits...but it would likely only be during Adds, because during an edit if an inactive item is already selected, you couldn't remove it (easily anyway).
See the sample for details.
Hope this helps!
|
By Edhy Rijo - 9/9/2008
Hi Greg,Thanks for this sample. I think this kind of implementation is more for a subclassed combobox due to all the code needed to make it work. I do like your approach, even though I think I would prefer to show only active items during adding. At the beginning I was thinking on using the BO.Filter to accomplish this in a less invasive way.
|
By Greg McGuffey - 9/9/2008
Hi Edhy,
I agree that a subclass would be a good way to go. I just wanted to do a proof of concept, to show how it could work. Another way to do it would be to make a component that has this code. Then you could just add the component to a form were you needed it, set a combo property and you're good to go. Thus you could add this to existing combos without having to change them. However, it could get complicated as you'd need to generalize how to determine active/inactive (or whatever state that is needed) based on an arbitrary BO(s) and field(s). I'd probably wait until I'd done this a couple of times before attempting that.
I'm not sure how much I like this approach (disabling selection, changing display of active/inactive items), myself (just wondered how it could be done). Showing only those valid items when adding seems like a good approach, as it doesn't confuse the user with old data. However, it gets complicated during edits, as you need the inactive values in the combo because they might already be assigned, but you don't want the user to be able to change to another inactive value. It also could be confusing that the user can't select some values. I'd probably provide an optional message indicating why they can't select an inactive item. I also noticed that the font/style of the text of the combo isn't affected by DrawItem. I'd probably also handle setting the font if the combo based on if the item is active or inactive.
In any case, lots of ideas on how to get this done at least!
|
By Aaron Young - 9/10/2008
Hi all,I don't know if this helps but if you are using the Infragistics controls you can easily change the row colour for inactive records. Initially, we only showed active items in our lists but we found this resulted in a number of support calls complaining that our application was failing to show apparently valid records, etc. Given the nature of our support contracts this resulted in someone remoting into the customers system only to find the record was inactive all the time. By color coding the record the user has a visible indication and you can trap the event even if the user attempts to select an inactive record (with SF I guess you could use broken rules). For some lists we have several different colours, i.e. a customer could be inactive or temporarily onhold due to payment problems with a different colour for each condition. Showing all records but informing the user that some are inactive with a different colour has cut down on wasted support calls when the user can't see the record and doesn't think of checking if it is inactive. Just my two cents worth
|
By Edhy Rijo - 9/10/2008
Hi Aaron,That is also a good idea and the way VFP combo works as Marcia was requesting, by disable the item. I also found color coding on listviews come out pretty good, but only if you are consistent with all color coding used in the application.
|
|