Depending on what options a user has picked in the configuration certain dynamic lists for combo boxes may only have 1 item. I want to automatically select the only choice in those cases. I am using the following code to do so:
if (Inputs.CmbPanel.Control.Rows.Count == 1)
{
Inputs.CmbPanel.Value = Inputs.CmbPanel.Control.Rows[0].Cells[0].Text;
Refresh.DynamicList("CmbPanelLocation");
}
But this does not cuase the field changed event to fire as it would if a user selected the value. I tried calling Inputs.CmbPanel.Control.RaiseOnComboChanged(); myself but that didn’t run the code in my event handler either. Any ideas?
You can trick it in a few ways. You can probably just give focus to another control - SomeTextBox.Focus();
You could set the value in the EpiDataView to which that control is bound and then call a Notify().
Another thing to consider, you are setting the Value of that combo by using the Text. Is this a multi column item? For example, the value can be different that the text in a multi column.
It properly changes the value (at least visually), but it doesn’t trigger the value changed event. I tried using the focus - it changes focus but my code still doesn’t run.
Could you give an example?
Maybe it would be best to just put my OnChanged code into a UD method and just manually call it in both places…
I think Chris is saying that the combobox has a .Text and a .Value property. MessageBox.Show(combo.Value) and MessageBox.Show(combo.Text) to compare any differences.
Sure I can give an example if you can tell me the epibinding of a combobox in question - although maybe I miss the point. My though is if your only problem is the field change isn’t firing - we can definitely get it to fire by changing the field ourselves.
What is actually triggering your code snippet in the first post? Also what is the purpose of the Refresh.DynamicList?
Also regarding Text vs Value - can you get us a snippet of your combo settings preferably DataMember and DisplayMember
Dan can’t you change the value of the input itself? Or do you not know what that value is?
Setting input.value to whatever should trigger the right events
You can change the value of another combo box without an issue but getting that destination combo box to fire its On Field Changed event does not seem to be working which can provide a cascading effect on the controls. I think that is what is being attempted here. Sound correct @Evan_Purdy. I swear I have had this working but cannot locate a good example or maybe I am thinking I did
Yes, exactly. I did try searching these forums but didn’t find anything. I did find the Inputs.CmbPanel.Control.RaiseOnComboChanged(); method via disassembler but it didn’t bring any success. I don’t know how to track down were it ends up calling my code, but I think that would give an idea on how to artificially induce it.
I looked through some work I had done before and I don’t think I ever figured this out because in a few cases I created a UD method and passed it the calling control for this event (On Field Changed). This was the best way that I could figure out at that time.
You could move your OnFieldChanged code to a Client UD method that returns void.
For example: OFC_CmbPanel
Then change the OnFieldChanged expression in the Designer to call that UD Method:
UDMethods.OFC_CmbPanel();
Now you can call this same UD method from inside your if block, or anywhere else as well.
One other note:
We’ve moved away from calling the Refresh.Dynamic list method once we figured out that a change to ANY input that is referenced in the DynamicList Condition expression (the one at the top that returns true/false as to whether that list will be used) causes the dynamic list to automatically refresh - even if the input has nothing to do with the condition. We found this to be the reason dynamic lists were refreshing multiple times. So if you want to refresh a combo box after a field changes (for example MyInput), simply reference it in the condition before returning true: