Hi Guys,
I've got a CSharp program that I'm working on but I can't get the ComboBoxColumn to display as I want it to.
I have two tables. One Contains a list of price. (Columns: PriceID, PartID, Price, MinimumQuantity, CustomerID, ExpiryDate) The other table, a list of parts contains (Columns: PartID, PartNumber). What
I want to do is display the PartNumber in a ComboBoxColumn with the PartID as the value. But I want to corresponding part number selected automatically for each price row.
Does this make sense!?
What I am currently getting in each row is the prices, quantities and expiry dates and ComboBoxColumn with the parts list populating the combobox but no value selected.
Please can someone help me with this.
Please see the code below.
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);
Then to generate the columns.
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);
}