当用户在文本框中输入PickingNoteNo时,我正在datagridview中显示数据。然后我以编程方式将两个combox添加到Datagridview并设置各自的Datasource。但是这些数据不会显示在Comboboxes.can中,请告诉我更改在我的代码中。
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";
}
}
}
在每一行中设置数据源后都有PackingID和ShippingID,我们需要为cmbBoxing的ComboBox和ShippingID设置Comboxes Selected值为PackingID.Later我们可以从组合框中选择一个新值并将数据保存到Database
1)如何在Combobox中填充数据。 2)如何从组合框中获取所选值。
还有一个要求。如果在Combobox中选择了值,即cmbpackingtype(数据如Cartons,Pallets,Boxes),那么我需要根据PackingID加载Combox cmbBox。
感谢。