1

当用户在文本框中输入 PickingNoteNo 时,我在 datagridview 中显示数据。然后我以编程方式将两个组合框添加到 Datagridview 并设置它们各自的数据源。但数据未显示在 Comboboxes 中。你能告诉我代码中的更改吗.

private void LoadDeliveryNoteDetails(string PickingNoteNo)
        {          

            dtDeliveryNoteDetails = new DataTable();
            try
            {
                using (QuotationBusiness objQuotationBusiness = new QuotationBusiness())
                {
                    dtDeliveryNoteDetails = objQuotationBusiness.GetDeliveryNoteDetails(PickingNoteNo);

                }
                if (dtDeliveryNoteDetails != null)
                {
                    gvDeliveryNoteDetails.DataSource = dtDeliveryNoteDetails;
                    HideGridViewColumns();
                    LoadCustomerDetails();
                    LoadDeliveryDetails();
                    LoadFreightDetails();
                    LoadPackagingTypeDetails();
                    LoadShippingBoxDetails();




                }

            }
            catch (Exception ex)
            {

            }
        }
        private void HideGridViewColumns()
        {
            foreach (DataGridViewColumn column in gvDeliveryNoteDetails.Columns)
            {
                if (column.Name != "ItemCode" && column.Name != "Quantity" && column.Name != "Description" && column.Name != "BatchNo"
                    && column.Name != "ExpiryDate" && column.Name != "Packaging Type")
                {

                    column.Visible = false;

                }
            }


        }


        private void LoadPackagingTypeDetails()
        {
            DataGridViewComboBoxColumn cmbpackingtype = new DataGridViewComboBoxColumn();
            cmbpackingtype.Name = "cmbPackingTypes";
            cmbpackingtype.HeaderText = "Packaging Type";
            gvDeliveryNoteDetails.Columns.Add(cmbpackingtype);

            using (QuotationBusiness objQB = new QuotationBusiness())
            {
                DataTable dtPackingTypes = objQB.GetPackagingTypeDetails();
                if (dtPackingTypes != null)
                {
                    DataRow row = dtPackingTypes.NewRow();
                    row["PackageType"] = "Select";
                    row["PackageTypeID"] = 0;
                    dtPackingTypes.Rows.InsertAt(row, 0);
                    cmbpackingtype.ValueMember = "PackageTypeID";
                    cmbpackingtype.DisplayMember = "PackageType";
                    cmbpackingtype.DataSource = dtPackingTypes;
                    cmbpackingtype.DisplayIndex = 0;


                }
            }

        }
        private void LoadShippingBoxDetails()
        {
            DataGridViewComboBoxColumn cmbBox = new DataGridViewComboBoxColumn();
            cmbBox.Name = "cmbBoxNos";
            cmbBox.HeaderText = "Box No";
            gvDeliveryNoteDetails.Columns.Add(cmbBox);
            using (EmployeeMasterBusiness objEmp = new EmployeeMasterBusiness())
            {
                DataTable dtBoxNos = objEmp.GetDepartmentDetails();
                if (dtBoxNos != null)
                {
                    DataRow row = dtBoxNos.NewRow();
                    row["DeptName"] = "Select";
                    row["DeptID"] = 0;
                    dtBoxNos.Rows.InsertAt(row, 0);
                    cmbBox.DataSource = dtBoxNos;
                    cmbBox.DisplayMember = "DeptName";
                    cmbBox.ValueMember = "DeptID";

                }
            }

        }

在每行设置数据源后,有 PackingID 和 ShippingID,我们需要将 Comboxes Selected 的值设置为 cmbpackingtype ComboBox 的 PackingID 和 cmbBox 的 ShippingID。稍后我们可以从组合框中选择一个新值并将数据保存到数据库。

1) 如何在组合框中填充数据。2)我如何从组合框中获取选定的值。

另外还有一个要求。如果在组合框中选择了该值,即 cmbpackingtype(Cartons、Pallets、Boxes 等数据),那么我需要根据 PackingID 加载 Combox cmbBox。

谢谢。

4

0 回答 0