Marvin Gapuz

Marvin Gapuz

  • NA
  • 85
  • 6.1k

Display data to datagridview

Mar 25 2019 8:38 AM
private void CmbCombo_SelectedValueChanged(object sender, EventArgs e)
{
try
{
if (CmbCombo.SelectedValue != null && CmbCombo.SelectedIndex != -1)
{
if (CmbCombo.SelectedValue.ToString() != string.Empty && CmbCombo.SelectedValue.ToString() != "System.Data.DataRowView")
{
ComboCreationSP creationSP = new ComboCreationSP();
ComboCreationInfo creationInfo = new ComboCreationInfo();
creationInfo = creationSP.ComboMasterViewAllForProduct(Convert.ToDecimal(CmbCombo.SelectedValue));
for (int a = 0; a < 2; a++)
{
dgvSalesInvoice.Rows.Add();
dgvSalesInvoice.Rows[a].Cells["dgvtxtSalesInvoiceProductName"].Value = creationInfo.ProductName;
dgvSalesInvoice.Rows[a].Cells["DcDescription"].Value = creationInfo.ProductName;
dgvSalesInvoice.Rows[a].Cells["dgvtxtSalesInvoiceBrand"].Value = creationInfo.PBrandId;
dgvSalesInvoice.Rows[a].Cells["dgvtxtSalesInvoiceQty"].Value = creationInfo.Qty;
dgvSalesInvoice.Rows[a].Cells["dgvtxtSalesInvoiceRate"].Value = creationInfo.Rate;
dgvSalesInvoice.Rows[a].Cells["dgvtxtSalesInvoiceProductCode"].Value = creationInfo.ProductCode;
dgvSalesInvoice.Rows[a].Cells["dgvtxtSalesInvoiceBarcode"].Value = creationInfo.Barcode;
}
txtTotalAmount.Text =Convert.ToString(creationInfo.Amount);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
 
Please help, I use this code to display the data from the database to the datagridview, the problem is that it only displays the last data. 

Answers (3)