DropDownList in a UltraGrid

We are in the process of converting from E9 to E10 and with that comes trying to recreate customizations that were created previously. I have been able to work my way through other features that had been created but I stomped by this one. Please provide a 100 Level solution as I am not a true programmer.

I have created the UltraGrid and I have the fields populating from the UD table; however, in E9 the fields where DropDowns which I can’t figure out the code to do so in my E10 customization. Your help is greatly appreciated.

Thanks.

UltraGrids in general are easier than many Epicor things to find help on - you can search online and find a lot of Infragistics documentation and discussion.

The accepted Epicor way, having said that, is as follows:

  • For any column in the grid that you would like to be a drop-down, add a Combo control of some kind elsewhere on the form and bind it to the same field. You can hide it afterwards if you don’t need it for anything else.
  • In InitializeCustomCode (or code called from there), add:
yourgrid.DisplayLayout.Bands[0].Columns["yourfield"].ValueList = yournewcontrol;
yourgrid.DisplayLayout.Bands[0].Columns["yourfield"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
yournewcontrol.ForceRefreshList();
6 Likes

Yes, I found a number suggests related to Infragistics online but they certainly didn’t match anything I was seeing in Epicor. Your code looks more familiar than it was to me. That being said I entered your code with my grid and control names as below in the InitializeCustomCode() section but when I opened the Form I received the Error below the my code.

epiUltraGridPltComm.DisplayLayout.Bands[0].Columns[“ShortChar01”].ValueList = epiComboRelPlant;

epiUltraGridPltComm.DisplayLayout.Bands[0].Columns[“ShortChar01”].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;

epiComboRelPlant.ForceRefreshList();

Application Error

Exception caught in: mscorlib

Error Detail

Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Key not found: ‘ShortChar01’
Parameter name: key
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod

Client Stack Trace

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeScriptMethod(MethodInfo scriptMethod, Object[] parameters)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeInitializeCustomCodeIfExists()
at Ice.Lib.Customization.CustomScriptManager.TryActionShowExceptionBoxOrLogVerificationErrorIfException(Action action, String exceptionBoxTitle)

Inner Exception

Key not found: ‘ShortChar01’
Parameter name: key

at Infragistics.Shared.KeyedSubObjectsCollectionBase.GetItem(String key)
at Infragistics.Win.UltraWinGrid.ColumnsCollection.get_Item(String key)
at Script.InitializeCustomCode()

That means there is no field of that name in the grid.

What did you bind the other control to? Does the field part of the binding match exactly?

I have included a screenshot from the Customization for your reference related to your latest reply as I understand it. So I went in and changed the code to be “UD09View.ShortChar01”, I received the same error but with the new field name.

That’s strange. It could be that the grid is not yet set up when InitializeCustomCode runs. It might be worth trying the same thing in the EpiNotification event for your UD09View instead.

Maybe slap a button on the form with a sanity check function:

//OnButtonClick
string myCols = "";
foreach(var col in epiUltraGridPltComm.DisplayLayout.Bands[0].Columns)
{
  myCols += col.Header.Key +" , "
}
MessageBox.Show(myCols);

If you see all the cols you expect, I’d focus on order of operations as @dhewi is mentioning above. The quickest check might be to move your logic from Initialize() to FormLoad()

Also, keep in mind, if you use any grouping, Bands[0] may not always be what you expect.

Thanks for the input. I was able to get it to work by using the code that Daryl provided in the Form_Load.

2 Likes

Something to be aware of: I got a dropdown working in an UltraGrid. Weeks later I wondered how users were still entering garbage. Turns out the UltraGrid still lets you paste-insert rows with invalid values for the dropdown field. I’ll probably write a BPM to fix or reject the bad data.

Edit: The reason I didn’t find out about this sooner is because the dropdown in the UltraGrid will usually display the garbage value. Only very rarely does it detect that the value is not valid and display blank, which the users notice. Meanwhile, the dropdown that it’s tied to (yournewcontrol in Daryl’s example above) displays blank as expected.

You might want to investigate Infragistics DropDownStyle options if this is a problem for you. It’s possible to make it so users can ONLY select from the list.

We don’t want to force users to select from the list. Apparently the CSRs are using paste-insert pretty often.

The dropdown I’m using is backed by a BAQ that provides UD codes and descriptions. I was thinking I could write a data directive to take the description pasted by the user and look up the code value. But the dropdown itself seems to be messing with the value. The behavior seems a bit random, so if it’s deterministic, I haven’t figured out how it works yet.

If the pasted value is a UD code value, then it always gets through to the BPM. If the pasted value happens to be the description shown in the dropdown on the previous line, then the pasted value often, but not always, reaches the BPM. If the pasted value is any other text, the value that reaches the BPM is usually, but not always, blank.

The original dropdown was (and still is) on the lines tab. The problem I was trying to solve was people typing garbage into the field in the grid. I’m leaning toward removing the dropdown from the grid and returning to a plain text field, but using a data directive to validate the input. This probably means the users will see the UD code instead of the description in the grid, but at least they’ll be able to paste using the familiar descriptions.

Not sure if anyone have encountered this, when I set the grid to use the EpiUltraCombo, the drop down list has no issue, but when I want to clear out the item using delete button, it doesn’t work, but then when the EpiUltraCombo is on the panel, then there is no issue using the delete button. Anyone knows the fix for it, please let me know.

This worked great for me with one exception. It seems that after selecting a value from the dropdown, the user must click or tab out of the box, otherwise the value does not stick when the row is saved. Any ideas?

Actually, it seems my issue was more due to how I was trying to save the record than something with the dropdown itself. I used an auto-tab to get around it for now

    private void myGrid_CellListSelect(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
    {
        System.Windows.Forms.SendKeys.Send("{TAB}");
    }
    ```
1 Like

I always have to look it up, but the ultragrid has a setting you can change which governs whether a cell edit affects the data as soon as it’s made or on exit. If you set it to the first, it does solve that problem, I believe.

It’s most annoying on checkboxes, because nobody ever expects to need to tab out of a checkbox.

2 Likes

@dhewi

This is what I’m looking for! However I have a question. I’m not the best at coding but I have a list of User Codes I made. Would it be possible to bind my user codes to the Solution provided? How would I wrtie that?

That part is about the combo itself. You can use an EpiCombo with BO of User Codes, and filter it to the CodeTypeID you’ve used, and that can all be done in the Properties panel so you don’t need code at all.

Or, sometimes, you may want to create a BAQ of your User Codes and use a BAQCombo. That works too.

Then the code in this thread will work to get the dropdown into a grid if you need.