Something you can try.
In future please only show the code of where the problem is occurring.
bool filled = false;
private void btnNew_Click(object sender, EventArgs e)
{
frmCreditSalesDetails frm = new frmCreditSalesDetails();
frm.Show();
}
private void frmDisplayCreditSales_Load(object sender, EventArgs e)
{
if(filled == false)
{
DataGridFill();
}
}
public static void DataGridFill()
{
dtpdisCreditSale.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
dtpdisCreditSale.CustomFormat = "dd MMMM,yyyy";
dtpdisCreditSale.Format = DateTimePickerFormat.Custom;
dtpFromDate.CustomFormat = "dd MMMM,yyyy";
dtpFromDate.Format = DateTimePickerFormat.Custom;
dtpToDate.CustomFormat = "dd MMMM,yyyy";
dtpToDate.Format = DateTimePickerFormat.Custom;
SqlDataAdapter daitems = new SqlDataAdapter("Select ItemID,ItemName from Items", con);
daitems.Fill(ds, "items");
SqlDataAdapter dacust = new SqlDataAdapter("Select CustomerID,CustomerName from Customers", con);
dacust.Fill(ds,"cust");
SqlDataAdapter dadt = new SqlDataAdapter("select s.SalesID,c.CustomerID,chd.SalesID,chd.ItemID,ch.ChallanID,ch.Date,s.FromDate,s.ToDate,chd.ItemName,chd.Description,chd.Rate,chd.Qty,(chd.Rate*chd.Qty) as Total from Challans ch inner join ChallanDetails chd on chd.ChallanID=ch.ChallanID inner join Sales s on s.CustomerID=ch.CustomerID inner join Customers c on c.CustomerID=s.CustomerID", con);
dadt.Fill(ds, "dt");
bndSoDisCrSale.DataSource = ds;
bndSoDisCrSale.DataMember = "dt";
cmbCustomerName.DisplayMember = "CustomerName";
cmbCustomerName.ValueMember = "CustomerID";
cmbCustomerName.DataSource = ds.Tables["cust"];
txtInvoiceNo.DataBindings.Add("Text", bndSoDisCrSale, "SalesID");
dtpdisCreditSale.DataBindings.Add("Value", bndSoDisCrSale, "Date");
cmbCustomerName.DataBindings.Add("SelectedValue", bndSoDisCrSale,"CustomerID");
dtpFromDate.DataBindings.Add("Value", bndSoDisCrSale, "FromDate");
dtpToDate.DataBindings.Add("Value", bndSoDisCrSale, "ToDate");
string sql = string.Format("select ch.Date,ch.ChallanID,chd.ItemName,chd.Description,chd.Rate,chd.Qty,(chd.Rate*chd.Qty) as Total from ChallanDetails chd inner join challans ch on ch.ChallanID=chd.ChallanID where chd.SalesID='{0}'", txtInvoiceNo.Text);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(ds, "gd");
grddiscrsale.DataSource = ds;
grddiscrsale.DataMember = "gd";
ds.Tables["gd"].RowChanged += new DataRowChangeEventHandler(frmDisplayCreditSales_RowChanged);
int total = 0;
for (int i = 0; i <= grddiscrsale.Rows.Count - 2; i++)
{
total += int.Parse(grddiscrsale.Rows[i].Cells["Total"].Value.ToString());
}
txtTotalPrice.Text = total.ToString();
filled = true;
}