Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Please let me know where I am going wrong in loading data in the DatagridviewComboboxColumn.

Below is the code.

HTML

C#
//Loading the DataGridview and adding the ComboBoxColumn using below method.


private void LoadDataGridview()
{


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

                }
                if (dtDeliveryNoteDetails != null)
                {
                    gvDeliveryNoteDetails.DataSource = dtDeliveryNoteDetails;
                    
  DataGridViewComboBoxColumn cmbpackingtype = new DataGridViewComboBoxColumn();
                    cmbpackingtype.Name = "cmbPackingTypes";
                    cmbpackingtype.HeaderText = "Packing Type";
                    cmbpackingtype.ReadOnly = false;                    
                    gvDeliveryNoteDetails.Columns.Add(cmbpackingtype);

///Loading Data into ComboBox                   
                    LoadPackagingTypeDetails(cmbpackingtype); 
                    
                }

            }
            catch (Exception ex)
            {

            }

 private void LoadPackagingTypeDetails(DataGridViewComboBoxColumn 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.DataSource = dtPackingTypes;  //using a datatable as Datasource to Combobox                 
                    cmbpackingtype.ValueMember = "PackageTypeID";
                    cmbpackingtype.DisplayMember = "PackageType";
                    cmbpackingtype.DefaultCellStyle.NullValue = "--Select--";
                   





                }
            }
}


But the ComboBox is not loading with the Data.When I click on the Combobox even the dropdown is not displayed.Just the --Select-- is displayed.How do we change the style to DropDownList and load the data.
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