Loading Comboboxes and Setting its value in each row in Datagridview

Posted by Nkkppp under C# on 3/25/2013 | Points: 10 | Views : 2249 | Status : [Member] | Replies : 4
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




Responses

Posted by: Jayakumars on: 3/25/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

check this both line datasource return or not. Ex(dataset or datatable return or not with debugging mode) otherwise attached ur project zip format. Then i solve ur issue.

gvDeliveryNoteDetails.DataSource = dtDeliveryNoteDetails;

DataTable dtPackingTypes = objQB.GetPackagingTypeDetails();

Mark as Answer if its helpful to you

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 3/25/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Its returning data but not displayed in the comboboxes.

Regards,
Prathap.

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/25/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
your

cmbpackingtype datasource not have check them


Mark as Answer if its helpful to you

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 3/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

I have noticed the problem.The Datagridview readonly property is true.Now I changed it to false and its working fine.Now i want to add another combobox CmbPackingNumber in Datagridview and when the cmbpackingtype selection is changed I want to load the related data into CmbPackingNumber combobox.How do we do this.I googled and tried few codes but didn't work.

Can you please help me with this.

Thanks.

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response