我有一个我正在研究的C#程序,但是我无法按照我想要的那样显示ComboBoxColumn。
我有两张桌子。一个包含价格清单。 (列:PriceID,PartID,Price,MinimumQuantity,CustomerID,ExpiryDate)另一个表,零件列表包含(列:PartID,PartNumber)。什么
我想要做的是在PartboBoxColumn中显示PartNumber,并将PartID作为值。但我想为每个价格行自动选择相应的零件编号。
这有意义吗??
我目前在每一行中获得的是价格,数量和到期日期以及ComboBoxColumn,其中零件清单填充了组合框但没有选择任何值。
请有人帮我这个。
请参阅以下代码。
DbConnection dbConn = new DbConnection(getConnectionStr());
dbConn.execQuery("EXEC RBS_CustomerSpecificPriceListSelect " + customerID + ";", "CustomerPriceList");
dbConn.execQuery("EXEC RBS_PartsSelect;", "Parts");
DataTable dtCustomerPrices = dbConn.getDataTable("CustomerPriceList");
DataTable dtParts = dbConn.getDataTable("Parts");
dgvCustomerPrices.AutoGenerateColumns = false;
dgvCustomerPrices.DataSource = dtCustomerPrices;
dgvCustomerPrices.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
SetupDGVColumns(dtCustomerPrices, dtParts);
然后生成列。
private void SetupDGVColumns(DataTable dtCustomerPrices, DataTable dtParts)
{
// Parts Dropdown
DataGridViewComboBoxColumn cboPartsColumn = new DataGridViewComboBoxColumn();
cboPartsColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
cboPartsColumn.DataSource = dtParts;
cboPartsColumn.HeaderText = "PartNumber";
cboPartsColumn.DisplayMember = "PartNumber";
cboPartsColumn.ValueMember = "PartID";
cboPartsColumn.DataPropertyName = "PartID";
cboPartsColumn.Width = 110;
cboPartsColumn.AutoComplete = true;
dgvCustomerPrices.Columns.Add(cboPartsColumn);
// MinimumQuantity Textbox
DataGridViewTextBoxColumn tbcMinimumQuantityColumn = new DataGridViewTextBoxColumn();
tbcMinimumQuantityColumn.DataPropertyName = "MinimumQuantity";
tbcMinimumQuantityColumn.HeaderText = "MinimumQuantity";
tbcMinimumQuantityColumn.ValueType = typeof(double);
tbcMinimumQuantityColumn.Width = 140;
tbcMinimumQuantityColumn.DefaultCellStyle.Format = "#####0.00";
dgvCustomerPrices.Columns.Add(tbcMinimumQuantityColumn);
// Price Textbox
DataGridViewTextBoxColumn tbcPriceColumn = new DataGridViewTextBoxColumn();
tbcPriceColumn.DataPropertyName = "Price";
tbcPriceColumn.HeaderText = "Price";
tbcPriceColumn.ValueType = typeof(double);
tbcPriceColumn.Width = 100;
tbcPriceColumn.DefaultCellStyle.Format = "#####0.00";
dgvCustomerPrices.Columns.Add(tbcPriceColumn);
// ExpiryDate Textbox
DataGridViewTextBoxColumn tbcExpiryDateColumn = new DataGridViewTextBoxColumn();
tbcExpiryDateColumn.DataPropertyName = "ExpiryDate";
tbcExpiryDateColumn.HeaderText = "ExpiryDate";
tbcExpiryDateColumn.ValueType = typeof(string);
tbcExpiryDateColumn.DefaultCellStyle.Format = "d";
dgvCustomerPrices.Columns.Add(tbcExpiryDateColumn);
}
答案 0 :(得分:0)
好的,这对我来说是完全白痴。选择组合列数据的SQL查询在SELECT子句中没有相应的行ID。
谢谢大家的帮助!我觉得很傻!