Button to search and return Partnum

I’m working on a custom Part Maintenance form that’s for a team to use to set the primary warehouse and bins. I basically hid all other tabs and have a custom blank sheet and created the relevant fields. The fields all work if manually entered but I wanted to mimic the standard buttons for Part and Bin search. I’ve done custom buttons with a search before to a UD field with similar code to below. But in this case it’s a standard table field, Part.PartNum but thought it’d work just a like a UD.

The code appears to work, clicking the button will open the Part Search dialog but the partnum isn’t passed back to the form. I’m sure I’m missing something stupid but can’t see what.

    {
   		this.btnPartSearch.Click += new System.EventHandler(this.btnPartSearch_Click);
    }

    private void btnPartSearch_Click(object sender, System.EventArgs args)
        {
            SearchOnPartAdapterShowDialog();
        }

    private void SearchOnPartAdapterShowDialog()
    {
        bool recSelected;
        string whereClause = string.Empty;
        System.Data.DataSet dsPartAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "PartAdapter", out recSelected, true, whereClause);
        if (recSelected)
        {
            System.Data.DataRow adapterRow = dsPartAdapter.Tables[0].Rows[0];

            // Map Search Fields to Application Fields
            EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
            System.Data.DataRow edvPartRow = edvPart.CurrentDataRow;
            if ((edvPartRow != null))
            {
                edvPartRow.BeginEdit();
                edvPartRow["PartNum"] = adapterRow["PartNum"];
                edvPartRow.EndEdit();
            }
        }
    }
2 Likes

Can you verify that selecting a record in the launched search returns a value? Show a msg or something from the dsPartAdapter row

I think the part number is being passed back (like @Aaron_Moreng said - debug this to be sure), but you’re not sending up a notification that the value has changed after the edit. Try adding a oTrans.NotifyAll(); after the edit for testing purposes and see if that changes things. If that works then pare it down to a targeted notification.

1 Like

I think you’re right, I think it’s because this is a fresh Part Maintenance form with no data loaded into the form yet.

I get message 1, 1a, and 2 but not 3 so it’s acting like no part was selected in the search.

        bool recSelected;
        string whereClause = string.Empty;
        System.Data.DataSet dsPartAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "PartAdapter", out recSelected, true, whereClause);
        if (recSelected)
        {
            System.Data.DataRow adapterRow = dsPartAdapter.Tables[0].Rows[0];
MessageBox.Show("1- recSelected: " + dsPartAdapter);
MessageBox.Show("1a- adapterRow: " + adapterRow);
            // Map Search Fields to Application Fields
            EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
MessageBox.Show("2- edvPart = " + edvPart);
            System.Data.DataRow edvPartRow = edvPart.CurrentDataRow;
            if ((edvPartRow != null))
            {
                edvPartRow.BeginEdit();
MessageBox.Show("3- AdapterRow = " + adapterRow["PartNum"]); 
                edvPartRow["PartNum"] = adapterRow["PartNum"];
                edvPartRow.EndEdit();
            }
        }

I took the plunge and just redid the form to keep the stock tabs I needed and disabled/hid all but the ones I needed. Not as pretty as my initial idea but no code needed and should work fine.

1 Like