Edit Integer field in grid

I want to be able to edit an integer field in a grid on a form with arrow up and down buttons instead of having to type it in. Is this possible?

No, it’s not supported out of the box. Do you want to show all numbers from -2,147,483,647 to 2,147,483,647? If you want a small number of static values, such as 1-10, an enum may be a good choice. If you want a small set of numbers generated at runtime, consider using a combobox and adding values from code. If it’s a reference to another table, maybe a surrogate key reference + reference group would be a better option than a relation directly over the int field.

Martin,

I like the idea of adding a range of numbers, something like 1 through 25 and I would like to add those in code. I have created a combobox in my grid on the form called cboTest. Do I overwrite the lookup method of that combobox? I’ve tried finding a good example of filling in the combobox but I can’t find one that works. Can you please help?

Assuming that your combobox has AutoDeclaration = Yes, you can fill your 25 values by this code:

int items = 25;
int i;

cboTest.items(items);

for (i = 1; i <= items; i++)
{
    cboTest.item(i);
    cboTest.text(int2str(i));
}

You can call it from init(), for example.

I put this in a a method called fillComboBox on the form

public void fillComboBox()
{
int items = 25;
int i;

cboTest.items(items);

for (i=1; i<=items; i++)
{
cboTest.item(i);
cboTest.text(int2str(i));
}
}

but when I run it, it tell me this:

FormComboBoxControl object not initialized.

Stack trace

(C)\Forms\TCI_ReceivingLabels\Methods\fillComboBox - line 6
(C)\Forms\TCI_ReceivingLabels\Methods\init - line 5
(C)\Classes\SysSetupFormRun\init - line 6
(C)\Classes\TCI_PurchGreenLabelsPrint\BasicReceivingLabels - line 11
(C)\Classes\TCI_PurchGreenLabelsPrint\run - line 19
(C)\Classes\TCI_PurchGreenLabelsPrint\main - line 70
(C)\Classes\FormFunctionButtonControl\Clicked

I think you call your method before initializing the form. Move the call of fillComboBox() below super().

You’re the best!

Martin,

I have one more quick question. I’ve written something on the selectionChange() of the combobox to write to the table what the user has chosen. It works perfectly an only the correct record is changed, yet on the form, the other combo boxes change to match the one I just changed. It doesn’t change what’s in the table but they all just show the same number. I would like them to show what is in the table so I’m assuming I need to do this in my fillComboBox method but how? I tried something like this but it’s not working:

public void fillComboBox()
{
int items = 25;
int i;

cboTest.items(items);

for (i=1; i<=items; i++)
{
cboTest.item(i);
cboTest.text(int2str(i));
}
while select table where table.ItemId == TCI_ReceivingLabels.ItemId
{
cboTest.selection(table.numofsmalllabels);
}
}

I think you’ll have to finally tell us what you’re trying to achieve. It’s difficult to provide a solution addressing all unknown requirements.

In either case, this would require a bound control, either to a field or to a method.

That form that opens is showing items from a table that I have populated. There is field in that table called NumOfSmallLabels but I don’t show that on the form/grid. I only show the item and the combo box that you helped me populate with numbers 1 to 25. I have written this on the selectionChange()
public int selectionChange()
{
int ret;

ret = super();

while select forupdate table where table.ItemId == TCI_ReceivingLabels.ItemId
{
if(table)
{
ttsBegin;
table.NumOfSmallLabels = str2int(cboTest.valueStr());
table.update();
ttsCommit;
}
}

return ret;
}
Like I said, this works perfectly and only changes NumOfSmallLabels for the item I change the comboBox on. But right after I change (let’s say the first item’s combobox) to “5”, and it writes it to the table, I then hover over any of the other comboboxes with my mouse, and they all change to “5”.

What I am ideally looking for is the combobox selection showing the same number that NumOfSmallLabels is equal to. I default that field to 1, so all the comboboxes should show “1” and shouldn’t change if one other combobox changes. Does this make sense? Sorry if I’m not being clear enough.

I understand the problem - it’s the expected behavior of this solution. But I can’t easily offer a better solution without understanding your business requirements.

For example, maybe it’s acceptable to simply move the field a group beside the grid.
Or if you need it in grid, you’ll have to use a different approach. As I mentioned, it requires a control bound to some source of data; it’s not enough for the whole column.

Okay, this is going back to my other thread then about Class to Form to Report. We have a form where a user chooses some PO’s, or whatever and chooses the items on it. They click a Print Receiving Labels button, and this calls a class that gathers all the info needed and writes it to a table called TCI_ReceivingLabels. For simplicity sake let’s say all it does is write the item to this table and default another field called NumOfSmallLabels to 1.

Next it opens a form and displays all these items and we put a combobox beside every item so the user can choose how many labels they want to print for each item. Some may stay at 1, others may change. I want the user to be able to easily change this number and click another button to print all the labels.

I have everything working the way it should…sort of. My first draft, I had the actual table field NumOfSmallsLabels being show instead of a combobox. I could edit every column to the number of labels I wanted, click Print and it opened my report with the exact amount of labels per item perfectly.

I didn’t find this very user friendly to have to click in the field and erase the default of number 1 and change it to what you wanted for every item. This is why I wanted to put in a combobox. I didn’t think user’s would print more than 25 so I asked for your help to create a combobox that fills with numbers 1-25. I don’t show the NumOfSmallsLabels field from the table anymore, just the combobox. In order for my print button to work, I needed to change the value of NumOfSmallsLabels in the table to equal the number they chose in the combobox. That’s when I wrote that code in selectionChange(). This works great too and only updates the record for the combobox I change. Like I said, the only weird thing now is the shown value of the other comboboxes showing the same value as the one I changed but the table remains with the correct info. This again is obviously not good because it will confuse the user.

Do you see a better solution for what I’m trying to do? Displaying all the items from a table on a form where the user can choose how many labels they want printed for each one of those items. In the future they will have 2 choices, small label and big label but right now I’m just working on small label. Like I said, most of this is working, I just need to find the right solution for the user to be able to pick how many labels they want to print. I just thought combobox would be most user friendly.

Do I understand correctly that the reason for building this whole thing instead of using a normal integer field is that they had to “erase the default of number 1”? It doesn’t sound like a big deal to me and using a combobox looks to me like giving up quite a few useful features. If I was designing this solution, I would tell them that this is a bad idea in my opinion. We should rather look at how to resolve the problem they have, or at least perceive, regarding data input. The have to learn how to use AX interface anyway, because you can’t change all numeric fields in the whole AX.

Lol, well yes the combobox was my idea because when I had it just as the Integer Field, I found it not very easy to click in the field and change it. Perhaps I’m picky. It seems like you are saying the integer field works fine so the user can just use that…

Yes, I’m saying that IntEdit controls are designed for integer values and are used for that across AX. They can be directly bound to integer fields, you can use expressions there (e.g. 2*3), you can sort and filter by them, the whole value is selected when you “tab” into the control so you can simply press a number on your keyboard to change the value…
Of course, you’re free to use something else if it’s better in your particular case, but you should think carefully about implications. And as I said, if users don’t know how to effectively use IntEdit controls, replacing a single instance with something else (and leaving the rest of AX intact) doesn’t really solve the problem.

Okay, I have switched it back to an IntEdit field and I have everything working the way I want it. My next challenge is to create another IntEdit field (NumOfLargeLabels) and call a second report sending it those labels…I’ll probably post something in the future regarding that. Thanks for all your help Martin. You have done a lot for me on this project :slight_smile: