Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DataGrid WinForm
Hi,
 
Please let me know where I am going wrong in loading data in the DatagridviewComboboxColumn.
 
Below is the code.
 
//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 25-Mar-13 3:15am

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 25 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