Selecting combobox item in customization code

I’m pretty close on this but there’s one last problem. I’ve added an BAQcombo to the Part form and populated it with a query that retrieves all the SalesCatID and Description fields from SalesCat. The SalesCatID is the value field that is bound to ShortChar01. The idea is that the sales category gets set for each part. So far, so good.
When a part is added to a sales order line, I want to select the Sales Category combobox entry based on the value from the part table. I have a BAQ that gets ShortChar01 from the part table filtered by part number. I then set the value of the Sales Category combobox to that value from the part table. The only problem is that the Sales Category combo on order entry doesn’t display the correct description until you drop down the combo. Once you drop it, it immediately selects the correct item.

Here’s my code (mostly appropriated from Jose’s YouTube)

private void OrderDtl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
	// ** Argument Properties and Uses **
	// args.Row["FieldName"]
	// args.Column, args.ProposedValue, args.Row
	// Add Event Handler Code
	switch (args.Column.ColumnName)
	{
		case "PartNum":
	Ice.Lib.Framework.EpiTextBox PartNumTextBox;
	PartNumTextBox = (EpiTextBox)csm.GetNativeControlReference("b7505712-6225-4cce-90bb-c39ee8c9efae");
	Ice.Lib.Framework.EpiCombo SalesTypeCombo;
	SalesTypeCombo = (EpiCombo)csm.GetNativeControlReference("75f5323e-199c-44c1-bf11-d74945f5f8a1");

	DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
	dqa.BOConnect();
	Ice.BO.QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("OG_GetPartSalesType");
	qeds.ExecutionParameter.Clear();
	qeds.ExecutionParameter.AddExecutionParameterRow("PartNumber",PartNumTextBox.Text, "nvarchar",false,Guid.NewGuid(),"A");
	dqa.ExecuteByID("OG_GetPartSalesType",qeds);
	if (dqa.QueryResults.Tables["Results"].Rows.Count > 0)
		{
			DataRow resultrow = dqa.QueryResults.Tables["Results"].Rows[0];
			edvOrderDtl.dataView[edvOrderDtl.Row]["SalesCatID"]=resultrow["Part_Shortchar01"];
			edvOrderDtl.Notify(new EpiNotifyArgs(oTrans,edvOrderDtl.Row,edvOrderDtl.Column));
		}
	dqa.Dispose();
			break;
	}
}

}

Any pointers would be greatly appreciated.

After you’ve assigned the value you can use Reflection to force the DropDown to retrieve the combo values.

using System.Reflection;


MethodInfo mi = cmbLbl.GetType().GetMethod("retrieveNow", BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(cmbLbl, new object[]{true});

I think this would work as well from a quick glance.

Thanks for the response,Jose. A couple of questions. I assume that “cmbLbl” is to be replaced with the control I’m trying to manipulate, correct? However, if I substitute the control name (cboxxx) into the statement I get a compile error that it doesn’t exist. How should I be referring to the combobox that I want to update?

Thanks, Dan. I’ll give this a try.

@mmahrle I had a typo in post. I changed it to be correct now. oTrans.Update();

Yes you are correct, you’ll need to get a hold of the combo box by using the csm object like this

var myComobo  = (EpiCombo)csm.GetNativeControlReference("YourControlsGuid");

Yes, that’s what I tried but it didn’t make any difference. The combo still doesn’t display the selection.

Ok, It works now, but I had to use both your methods. Either by itself didn’t make the selection display. Taking a “why not” approach I included both the reflection and the oTrans.Update() and that did the trick. Thanks, both of you.