I have created an Extended UD Field (FinishSteps_c) on a UD Table (UD01) that derives it’s value from a User Code(UD01.STEPS) referenced on the field’s extended properties. When adding new rows to this table, users will be using the list view to fill in all the required fields. When selecting the FinishSteps_c field, I would like a drop down list to display with only the available codes from UD01.STEPS. I am trying to accomplish this using this method, but I keep receiving this error when I load the customization:
Error Detail
============
Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Key not found: 'FinishSteps_c'
Parameter name: key
What’s odd is that I only receive this error when the referenced column is an extended UD Field. If I specify a Custom Field like Character08 or a Key field it works without issue. I’ve attached my code for reference. Any help would be greatly appreciated as this issue has me stumped.
Has a full data regen and IIS reset performed since adding that field? It seems like the column name you are using doesn’t exist - for troubleshooting I’d maybe try:
foreach(var col in myGridList.DisplayLayout.Bands[0].Columns)
{
MessageBox.Show(col.Name);
}
This way you can at least see what the col name is being set as. It doesn’t solve the problem, just gets us more info to process
A data regen was performed by the SaaS team (I’m not sure about IIS as the server is managed by Epicor) and all tables and data models are in sync. When I try your suggested code I receive this error:
Error Detail
Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Object reference not set to an instance of an object.
I see - I think the issue may be the order of operations then. If you are trying to run your code before the grid has been populated by a dataset, it will not contain header names.
What actually populates your grid? a baq? code?
Perhaps you could use the event that fires when the grids datasource changes like:
You are correct. Running code on form load with no data available returns a whole lot of nothing.
I believe that I have it working correctly now. I used the Form Event Wizard to add an AfterAdapterMethod handler and changed the method name in the Case statement to “GetRows”. I then moved my original code below the Case and am now seeing the intended results. However, I’ve run into a new issue now that has me stumped.
Here is the relevant code I added to through the Event Wizard:
private void oTrans_adapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **
// ** Use MessageBox to find adapter method name
//EpiMessageBox.Show(args.MethodName);
switch (args.MethodName)
{
case "GetaNewUD01":
case "GetRows":
myGridList = (EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
myGridList.DisplayLayout.Bands[0].Columns["FinishSteps_c"].ValueList = Combo1;
break;
}
}
I added the case “GetaNewUD01”: to handle new record creation (in case the user doesn’t search for records first), but for some reason this method isn’t working. I tried using the EpiMessageBox.Show, but it doesn’t display the method when I create a new record. I ran a trace and was able to verify that the method is being used though. Any ideas?
The best advice I can give is to uncomment the line in the code that shows the MethodName being called. This way you can confirm the naming. It will be messy as hell with a ton a popups but once you confirm the MethodName you can remove it.
If you don’t see the expected method on create, well… Let’s cross that bridge if we reach it.
I uncommented the line and ran the customization, but when I clicked New to create a record I didn’t receive a message box. I tried saving and deleting the record, both of which resulted in a message box displaying the correct methods (update, delete) so I know that the code is working.
Ok, that must mean that isn’t the same adapter being used to create the record.
We could try to attack this a different way. Is there an EpiDataView on the form related to UD01? If so,
myDataView.ListChanged += (sender, args) =>
{
if (args.ListChangedType == ListChangedType.ItemAdded)
{
//do something with your grid
// (sender as EpiDataView).Table.Rows[args.NewIndex]["Key1"] = "YourKey1"; //example changing a value
}
}
Everything works as intended. I now have a drop down list available when a search is performed and when a new record is added to the table. Thank you very much for your help. I really appreciate it.
Combo1 is the name I gave to a combo box that I added to the form. The last line of code defines the fields in the FinishSteps_c column as a ValueList that use the values from Combo1 as the datasource. At least that’s what I believe is happening.
// Create a value list with the key of VL1.
ValueList valueList = this.ultraGrid1.DisplayLayout.ValueLists.Add( "VL1" );
// Add some items to it. Here the items added have numeric data values and
// associated display texts. What the user sees in the cells is the display
// text for these underlying numeric data value. Also when the user modifies
// a cell and selects one of the item, what goes in the data source is the
// associated numeric value.
valueList.ValueListItems.Add( 1, "One" );
valueList.ValueListItems.Add( 2, "Two" );
valueList.ValueListItems.Add( 3, "Three" );
valueList.ValueListItems.Add( 4, "Four" );
valueList.ValueListItems.Add( 5, "Five" );