Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I am displaying the data in datagridview when user enters PickingNoteNo in the textbox.Then i am adding two comboxes to the Datagridview programatically and setting their respective Datasource.But the data is not displayed in the Comboboxes.can you please tell me changes in my code.

C#
<pre lang="HTML"> 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";
    
                    }
                }
    
            }


After setting the datasource in every Row there is PackingID and ShippingID and we need to set the Comboxes Selected value to PackingID for cmbpackingtype ComboBox and ShippingID for cmbBox.Later we can select a new value from the comboboxes and save the data to Database.


1) How do I populate data in Comboboxes.
2) How do i get the selected value from the combobox.


Also there is one more requirement.If the value is selected in the Combobox i.e cmbpackingtype (data like Cartons,Pallets,Boxes) then I need to load the Combox cmbBox depending on PackingID.

Thanks.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900