Skip to Content
avatar image
Former Member

Disable specific field on custom form UI API

Hello everybody,

I have created a custom form using SAP Business One Studio for Visual Studio and have attached a Matrix on this form. I have added three ComboBoxes as fields and populate them with specific values stored in a table. When the form is loaded Form's ComboBoxes are populated based on the values stored in SQL tables.

My issue now is that I would like to disable the third ComboBox after it's value is selected in order to prevent users from changing it's value.

Here is the code I use to populate my Form once initialized

foreach (var s in GetSettings())
                {
                    oComboBox = (SAPbouiCOM.ComboBox)this.Matrix1.Columns.Item("oTy").Cells.Item(j).Specific;
                    oComboBox.Select(s.Item1);
                    oComboBox = (SAPbouiCOM.ComboBox)this.Matrix1.Columns.Item("oUs").Cells.Item(j).Specific;
                    oComboBox.Select(s.Item2);
                    oComboBox = (SAPbouiCOM.ComboBox)this.Matrix1.Columns.Item("oAc").Cells.Item(j).Specific;
                    oComboBox.Select(s.Item3);
oComboBox.Item.Enabled = false;
                    this.Matrix1.AddRow();
                    j++;
                }

Have also tried to disable previous line ComboBox but again got the same exception saying that field got focus and can not be disabled.

Any help solving this issue will be much appreciated.

Kind regards,

Dimitris Theotokatos

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 13, 2017 at 12:45 PM

    Hello Diego,

    I tried your suggestion but still got the same exception.
    I finally managed to solve my problem by using Item Event and when a user tries to click the combo box to change it's value, then another click is performed on form from UI API disabling user to change the original value.

    It is not the best solution, I suppose, but what I found out is that UI API can not disable specific rows/fields but only columns, so this is the best solution I figured out so far.

    Thanks for your help and your time.

    Kind regards,

    Dimitris Theotokatos

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 13, 2017 at 12:06 PM

    Hi Dimitris,

    You need move the focus to another field before disable the field.

    In your case you can do this with a click in the next or previous column:

    this.Matrix1.Columns.Item("oUs").Cells.Item(j).Click();

    Hope it helps.

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded