0
我想以另一種形式更新問題加載從DataGridView到組合框的數據加載到組合框是具體的項目不被在對產品編號產品組合框有什麼解決辦法,請幫忙選擇如何將數據從DataGridView
// Code of gridview form
private void invoiceItemsDetailsDataGridView_DoubleClick(object sender, EventArgs e)
{
int index = invoiceItemsDetailsDataGridView.Rows.GetFirstRow(DataGridViewElementStates.Selected);
//string productid = invoiceItemsDetailsDataGridView.Rows[index].Cells["ProductId"].Value.ToString();
//string productName = invoiceItemsDetailsDataGridView.Rows[index].Cells["ProductName"].Value.ToString();
invoiceItemDetailChangeForm icf = new invoiceItemDetailChangeForm();
icf.CurrentQuantity = Convert.ToUInt16(invoiceItemsDetailsDataGridView.Rows[index].Cells["Quantity"].Value);
icf.ProductId = Convert.ToUInt16(invoiceItemsDetailsDataGridView.Rows[index].Cells["ProductID"].Value); ;
icf.ShowDialog();
}
//一流水平的invoiceItemDetailChangeForm聲明INT更新invoiceItemDetailChangeForm形式與組合框
public int CurrentQuantity { get; set; }
public int ProductId { get; set; }
//代碼
private void invoiceItemDetailChangeForm_Load(object sender, EventArgs e)
{
QtyTextBox.Text = CurrentQuantity.ToString();
ProductNameComboBox.SelectedValue = ProductId;
ProductNameComboBox.DisplayMember = "ProductName";
ProductNameComboBox.ValueMember = "ProductID";
ProductNameComboBox.DataSource = GetAllProducts();
//ProductNameComboBox.SelectedValue = -1;
}
private object GetAllProducts()
{
DataTable dtProducts = new DataTable();
string connString = ConfigurationManager.ConnectionStrings["dbZ"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlCommand cmd = new SqlCommand("usp_GetAllProductsForPOS", conn))
{
cmd.CommandType = CommandType.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
dtProducts.Load(reader);
}
}
return dtProducts;
}
感謝克里斯現在它的工作原理非常感謝你!!!! –
@ShafqatRaza歡迎歡迎編碼 – Krishna