Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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.
 
<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 22-Mar-13 3:13am

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100