Populating own UltraComboEditor with custom field combo  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Populating own UltraComboEditor with custom field combo

Postby DannyC » Tue Jun 10, 2025 11:45 pm

Sort of along the lines of this older thread viewtopic.php?f=26&t=2410

I have a custom field combo and have set the list values in the
Code: Select all
#region "CustomFieldPlugin"


I want to duplicate the combo in the main header area with an UltraComboEditor (for purposes of this thread it doesn't really matter if its inventory, sales orders, purchase orders or whatever).
The value that is currently saved in the custom field I want to display when the record is Read (i.e. at ReadEnd).
If the user changes the dropdown in the main header I want that reflected in the custom field.
If the user changes the value in the custom field, I want that reflected in the header UltraComboEditor.

Ideally I want to set the list values in one place, namely the #region "CustomFieldPlugin"

Its a slightly different question to the old one referred above as the old one has the item list values repeated for the custom field and the UltraComboEditor. I just want to set them in one place.
And the plugin in the old thread doesn't reflect in either/both combos when the other has changed.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Populating own UltraComboEditor with custom field combo

Postby SBarnes » Wed Jun 11, 2025 9:36 am

Courtesy of ChatGPT the following code as a winforms example should be enough to get you started, I made sure the example included putting the combo editor on a panel and the value chaged event which will detect the user picking a value.


Code: Select all
using System;
using System.Windows.Forms;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.Misc;

namespace InfragisticsExample
{
    public class MainForm : Form
    {
        private UltraPanel ultraPanel;
        private UltraComboEditor ultraComboEditor;

        public MainForm()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.ultraPanel = new UltraPanel();
            this.ultraComboEditor = new UltraComboEditor();

            this.SuspendLayout();

            //
            // ultraPanel
            //
            this.ultraPanel.Dock = DockStyle.Fill;
            this.ultraPanel.Location = new System.Drawing.Point(0, 0);
            this.ultraPanel.Name = "ultraPanel";
            this.ultraPanel.Size = new System.Drawing.Size(400, 200);
            this.ultraPanel.TabIndex = 0;

            //
            // ultraComboEditor
            //
            this.ultraComboEditor.Location = new System.Drawing.Point(50, 50);
            this.ultraComboEditor.Name = "ultraComboEditor";
            this.ultraComboEditor.Size = new System.Drawing.Size(200, 21);
            this.ultraComboEditor.TabIndex = 1;

            // Add items
            this.ultraComboEditor.Items.Add("Apple");
            this.ultraComboEditor.Items.Add("Banana");
            this.ultraComboEditor.Items.Add("Cherry");

            // Subscribe to the ValueChanged event
            this.ultraComboEditor.ValueChanged += UltraComboEditor_ValueChanged;

            // Add the combo editor to the panel
            this.ultraPanel.ClientArea.Controls.Add(this.ultraComboEditor);

            // Add the panel to the form
            this.Controls.Add(this.ultraPanel);

            //
            // MainForm
            //
            this.ClientSize = new System.Drawing.Size(400, 200);
            this.Name = "MainForm";
            this.Text = "UltraComboEditor ValueChanged Example";

            this.ResumeLayout(false);
        }

        // Event handler for ValueChanged
        private void UltraComboEditor_ValueChanged(object sender, EventArgs e)
        {
            string selectedItem = ultraComboEditor.Text;
            MessageBox.Show($"You selected: {selectedItem}", "Selection Changed");
        }

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new MainForm());
        }
    }
}

Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Populating own UltraComboEditor with custom field combo

Postby DannyC » Wed Jun 11, 2025 10:02 am

I don't have any problem adding the UltraComboEditor to the form. Already done that, in fact much of my current code reads like yours.
My issue is with the following lines
Code: Select all
// Add items
this.ultraComboEditor.Items.Add("Apple");
this.ultraComboEditor.Items.Add("Banana");
this.ultraComboEditor.Items.Add("Cherry");


I don't want to add the items one by one. I already have them defined in the custom field, so I want the UltraComboEditor to read from there rather than repeating the items and potentially missing edits if they change down the track.
And furthermore, it is seeing the changes in the one or the other when changes are made.

I have basically completed the plugin, just those 2 questions are outstanding.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Populating own UltraComboEditor with custom field combo

Postby SBarnes » Wed Jun 11, 2025 10:15 am

Items should be a list so you may find addrange is an option
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Populating own UltraComboEditor with custom field combo  Topic is solved

Postby Mike.Sheen » Wed Jun 11, 2025 11:20 am

DannyC wrote:Ideally I want to set the list values in one place, namely the #region "CustomFieldPlugin"


Create a static (shared in VB) class with a static property or method which either just defines the list, or accepts a combo control as a parameter and populates the controls value list - being static it will be accessible from everywhere.

So you will then have one place to define the list of items.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Populating own UltraComboEditor with custom field combo

Postby DannyC » Wed Jun 11, 2025 5:43 pm

Mike, I understand the concept I think but never done it.
I have created this class

Code: Select all
public static class ComboBoxHelper
{
    public static void PopulateMyCombo(System.Windows.Forms.ComboBox mycomboBox)
    {
        mycomboBox.Items.Clear();
        mycomboBox.Items.AddRange(new string[]
        {
            "Phone",
            "Tablet",
            "Scanner",
            "Notepad"
        });
    }
}


So then in the custom field region, I would do something like this?
Code: Select all
public void FormatCell(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.IJiwaCustomFieldValues HostObject, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomField CustomField, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue CustomFieldValue)
{
   if (CustomField.PluginCustomField.Name == "Device" && FormObject.Form.Name == "BaseSalesOrderEntryForm")
   {
      FarPoint.Win.Spread.CellType.ComboBoxCellType cellType = new FarPoint.Win.Spread.CellType.ComboBoxCellType();      
      
      List<string> items = new List<string>();
      foreach (var item in ComboBoxHelper.mycomboBox)
      {
         items.Add(item.ToString());
      }

      cellType.Items = items.ToArray();
      cellType.ItemData = items.ToArray();
      
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData;
   }      
}

How do I get the ComboBoxHelper combo box items into the custom field combo?
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Populating own UltraComboEditor with custom field combo

Postby DannyC » Wed Jun 11, 2025 6:27 pm

Decided on a different tack.
Code: Select all
public static class MyInvoiceTypes
{
    // Define a static list of items
    public static readonly List<string> Devices = new List<string>
    {
        "Phone",
        "Tablet",
        "Scanner",
        "Notepad"
    };
}


then in the custom field...
Code: Select all
    public void FormatCell(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.IJiwaCustomFieldValues HostObject, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomField CustomField, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue CustomFieldValue)
    {
      if (CustomField.PluginCustomField.Name == "Device" && FormObject.Form.Name == "BaseSalesOrderEntryForm")
      {
         FarPoint.Win.Spread.CellType.ComboBoxCellType cellType = new FarPoint.Win.Spread.CellType.ComboBoxCellType();      
         
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData;
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).Items = MyInvoiceTypes.Devices.ToArray();
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).ItemData = MyInvoiceTypes.Devices.ToArray();            
      }      
    }


That works nicely.

And I am able to populate the UltraComboEditor by enumerating the MyInvoiceTypes.Devices.

I even have one updating the other, so whole plugin is basically done.

Thanks for the tip Mike.
Last edited by DannyC on Wed Jun 11, 2025 6:43 pm, edited 1 time in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Populating own UltraComboEditor with custom field combo

Postby Mike.Sheen » Wed Jun 11, 2025 6:29 pm

DannyC wrote:Decided on a different tack.
Code: Select all
public static class MyInvoiceTypes
{
    // Define a static list of items
    public static readonly List<string> Devices = new List<string>
    {
        "Phone",
        "Tablet",
        "Scanner",
        "Notepad"
    };
}


then in the custom field...
Code: Select all
    public void FormatCell(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.IJiwaCustomFieldValues HostObject, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomField CustomField, JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue CustomFieldValue)
    {
      if (CustomField.PluginCustomField.Name == "Device" && FormObject.Form.Name == "BaseSalesOrderEntryForm")
      {
         FarPoint.Win.Spread.CellType.ComboBoxCellType cellType = new FarPoint.Win.Spread.CellType.ComboBoxCellType();      
         
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData;
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).Items = MyInvoiceTypes.InvoiceTypes.ToArray();
         ((FarPoint.Win.Spread.CellType.ComboBoxCellType)GridObject.ActiveSheet.Cells[Row, Col].CellType).ItemData = MyInvoiceTypes.InvoiceTypes.ToArray();            
      }      
    }


Nice and clean and simple!
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Populating own UltraComboEditor with custom field combo

Postby DannyC » Thu Jun 12, 2025 12:36 am

In the interest of sharing the love, here's the completed plugin should anyone care for it.
It replaces the System Setting Invoice Type which only allows 2 options.
Attachments
Plugin Attkey Custom InvoiceType.xml
(37.95 KiB) Downloaded 529 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 5 guests