on 2020 Aug 13 11:39 AM
Hello
I'm newbie to SAP Business One Visual Studio programming.
In my project i need to fill ComboBox with Item Categories name and code.
The problem is when i try to pass value from Datasource to ComboBox.ValidValues I'm getting an NullReferenceException.
Here is my code:
private void Form_LoadAfter(SAPbouiCOM.SBOItemEventArg pVal)
{
Form oForm = null;
oForm = SAPbouiCOM.Framework.Application.SBO_Application.Forms.Item(pVal.FormUID);
oForm.DataSources.DataTables.Add("Item_data");
SAPbouiCOM.DataTable dt = oForm.DataSources.DataTables.Item("Item_data");
dt.ExecuteQuery("SELECT Code,Name FROM [@ITEMCATEGORY]");
for (int i = 0; i < dt.Rows.Count; i++)
{
string oCode = dt.Columns.Item("Code").Cells.Item(i).Value.ToString();
string oName = dt.Columns.Item("Name").Cells.Item(i).Value.ToString();
try
{
Debug.WriteLine("Code: "+oCode+" Name: "+oName);
ComboBox0.ValidValues.Add(oCode,oName);
}
catch(Exception ex)
{
}
}
}
Any kind of help will be appreciated.
Thank you
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Moved the loop which was adding values to ValidValues to OnInitializeComponent().
Now everything is working thanks for the info.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Make sure your ComboBox0 is not null.
Your code did not show where you initialize this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
public override void OnInitializeComponent()
{
this.StaticText0 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_0").Specific));
this.StaticText1 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_1").Specific));
this.StaticText2 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_2").Specific));
this.StaticText3 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_5").Specific));
this.StaticText4 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_6").Specific));
this.StaticText5 = ((SAPbouiCOM.StaticText)(this.GetItem("Item_7").Specific));
this.EditText2 = ((SAPbouiCOM.EditText)(this.GetItem("Item_8").Specific));
this.EditText3 = ((SAPbouiCOM.EditText)(this.GetItem("Item_9").Specific));
this.Button0 = ((SAPbouiCOM.Button)(this.GetItem("Item_10").Specific));
this.Button0.ClickAfter += new SAPbouiCOM._IButtonEvents_ClickAfterEventHandler(this.Button0_ClickAfter);
this.Button1 = ((SAPbouiCOM.Button)(this.GetItem("Item_11").Specific));
this.Button1.ClickAfter += new SAPbouiCOM._IButtonEvents_ClickAfterEventHandler(this.Button1_ClickAfter);
this.ComboBox0 = ((SAPbouiCOM.ComboBox)(this.GetItem("Item_13").Specific));
this.EditText4 = ((SAPbouiCOM.EditText)(this.GetItem("Item_15").Specific));
this.OnCustomInitialize();
}
Here is the initialization part. And yes ComboBox is null but i can't seem insert anything.
Try logging onto the data source before getting the collection.
I fill list boxes this way:
LstInterpolationMode.Enabled = true;
Array CRinterpolationMode = Enum.GetValues(typeof(System.Drawing.Drawing2D.InterpolationMode));
foreach (object obj in CRinterpolationMode)
{
LstInterpolationMode.Items.Add(obj);
}
LstInterpolationMode.SelectedItem = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 32 | |
| 17 | |
| 16 | |
| 6 | |
| 5 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.