/// <summary>
 /// Function to call frmPdcReceivable form to set amount for sundry creditors or sundry debtors
 /// </summary>
 /// <param name="frmPDCreceivable"></param>
 /// <param name="decId"></param>
 /// <param name="dtblPartyBalance"></param>
 /// <param name="decPdcReceivableVoucherTypeId"></param>
 /// <param name="strVoucherNo"></param>
 /// <param name="date"></param>
 public void CallThisFormFromPDCReceivable(frmPdcReceivable frmPDCreceivable, decimal decId, DataTable dtblPartyBalance, decimal decPdcReceivableVoucherTypeId, string strVoucherNo, DateTime date)
 {
     try
     {
         decVoucherTypeId = decPdcReceivableVoucherTypeId;
         this.strVoucherNo = strVoucherNo;
         decLedgerId = decId;
         // inRowIndex = inIndex;
         this.dtblPartyBalance = dtblPartyBalance;
         strDebitOrCredit = "Cr";
         base.Show();
         this.frmPdcReceivableObj = frmPDCreceivable;
         frmPdcReceivableObj.Enabled = false;
         int inTableRowCount = dtblPartyBalance.Rows.Count;
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         PartyBalanceInfo InfoPartyBalance = new PartyBalanceInfo();
         List<DataTable> listObj = new List<DataTable>();
         if (inTableRowCount > 0)
         {
             int inK = 0;
             for (int inI = 0; inI < inTableRowCount; inI++)
             {
                 if (decLedgerId == Convert.ToDecimal(dtblPartyBalance.Rows[inI]["LedgerId"].ToString()))
                 {
                     if (strDebitOrCredit == dtblPartyBalance.Rows[inI]["DebitOrCredit"].ToString())
                     {
                         dgvPartyBalance.Rows.Add();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value = dtblPartyBalance.Rows[inI]["ReferenceType"].ToString();
                         if (dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value.ToString() == "Against")
                         {
                             //----------------------------------------------------------------------------//
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].ReadOnly = false;
                             listObj = BllPartyBalance.PartyBalanceComboViewByLedgerId(decLedgerId, strDebitOrCredit, decVoucherTypeId, strVoucherNo);
                             DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbVoucherType"].Index, dgvPartyBalance.CurrentRow.Index - 1];
                             dgvccVoucherType.DataSource = listObj[0];
                             dgvccVoucherType.ValueMember = "value";
                             dgvccVoucherType.DisplayMember = "display";
                             //============================================================================//
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherTypeId"].ToString() + "_" + dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtVoucherNo"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtInvoiceNo"].Value = dtblPartyBalance.Rows[inI]["AgainstInvoiceNo"].ToString();
                             if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value != null && dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() != string.Empty)
                             {
                                 for (int inD = 0; inD < listObj[0].Rows.Count; inD++)
                                 {
                                     if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() == listObj[0].Rows[inD]["value"].ToString())
                                     {
                                         dgvPartyBalance.Rows[inK].Cells["dgvtxtpending"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[inD]["balance"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                         break;
                                     }
                                 }
                             }
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].ReadOnly = true;
                         }
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtAmount"].Value = Math.Round(Convert.ToDecimal(dtblPartyBalance.Rows[inI]["Amount"].ToString()), Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces)).ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtblPartyBalance.Rows[inI]["CurrencyId"].ToString());
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtPartyBalanceId"].Value = dtblPartyBalance.Rows[inI]["partyBalanceId"].ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtOldExchangeRateId"].Value = dtblPartyBalance.Rows[inI]["OldExchangeRate"].ToString();
                         inK++;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:13" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Fill the corresponding details of party and calculations on cell value changed 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvPartyBalance_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();

                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    if (dgvPartyBalance.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value == null || dgvPartyBalance.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value.ToString() == string.Empty)
                    {
                        dgvPartyBalance.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1);//decExchangeRateId;

                    }
                    if (dgvPartyBalance.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtAmount" || dgvPartyBalance.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbCurrency")
                    {
                        TotalAmount();
                    }
                    //---------------------check column missing---------------------------------//
                    CheckColumnMissing(e);
                    //==========================================================================//
                    if (dgvPartyBalance.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbReference")
                    {
                        if (dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value != null)//&& dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value.ToString() != string.Empty)
                        {
                            //to fill combo without filling the already selected value
                            if (dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value.ToString() == "Against")
                            {
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].ReadOnly = false;
                                if (frmJournalVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                                }
                                else if (frmPaymentVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Dr";
                                }
                                else if (frmReceiptVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Cr";
                                }
                                else if (frmPdcpayableObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Dr";
                                }
                                else if (frmPdcReceivableObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Cr";
                                }
                            }
                            else if (dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value.ToString() == "New")
                            {
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].ReadOnly = true;
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].Value = string.Empty;
                                dgvPartyBalance.CurrentRow.Cells["dgvtxtVoucherNo"].Value = null;
                                dgvPartyBalance.CurrentRow.Cells["dgvtxtPending"].Value = null;
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].ReadOnly = false;
                                if (frmJournalVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                                }
                                else if (frmPaymentVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Dr";
                                }
                                else if (frmReceiptVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Cr";
                                }
                                else if (frmPdcpayableObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Dr";
                                }
                                else if (frmPdcReceivableObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Cr";
                                }
                            }
                            //
                            else if (dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value.ToString() == "OnAccount")
                            {
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].ReadOnly = true;
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].Value = string.Empty;
                                dgvPartyBalance.CurrentRow.Cells["dgvtxtVoucherNo"].Value = null;
                                dgvPartyBalance.CurrentRow.Cells["dgvtxtPending"].Value = null;
                                dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].ReadOnly = false;
                                if (frmJournalVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                                }
                                else if (frmPaymentVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Dr";
                                }
                                else if (frmReceiptVoucherObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Cr";
                                }
                                else if (frmPdcpayableObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Dr";
                                }
                                else if (frmPdcReceivableObj != null)
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtCrDr"].Value = "Cr";
                                }
                            }
                        }
                    }
                    else if (dgvPartyBalance.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbVoucherType")
                    {
                        if (dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].Value != null && dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].Value.ToString().Trim() != string.Empty)
                        {
                            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
                            ExchangeRateInfo infoExchangeRate = new ExchangeRateInfo();
                            string str = dgvPartyBalance.CurrentRow.Cells["dgvcmbVoucherType"].Value.ToString();
                            string[] words;
                            words = str.Split('_');
                            List<DataTable> listObj = new List<DataTable>();
                            listObj = BllPartyBalance.PartyBalanceComboViewByLedgerId(decLedgerId, strDebitOrCredit, decVoucherTypeId, strVoucherNo);
                            for (int inD = 0; inD < listObj[0].Rows.Count; inD++)
                            {
                                if (dgvPartyBalance.Rows[e.RowIndex].Cells["dgvcmbVoucherType"].Value.ToString() == listObj[0].Rows[inD]["value"].ToString())
                                {
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtVoucherNo"].Value = listObj[0].Rows[inD]["voucherNo"].ToString();
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtPending"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[inD]["balance"].ToString()), PublicVariables._inNoOfDecimalPlaces);

                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtOldExchangeRateId"].Value = listObj[0].Rows[inD]["exchangeRateId"].ToString();
                                    if (Convert.ToDecimal(listObj[0].Rows[inD]["exchangeRateId"].ToString()) != 1m)
                                    {
                                        infoExchangeRate = BllExchangeRate.ExchangeRateView(Convert.ToDecimal(listObj[0].Rows[inD]["exchangeRateId"].ToString()));
                                        decimal decCurrentExchangeRateId = BllExchangeRate.GetExchangeRateId(infoExchangeRate.CurrencyId, dtmVoucherDate);
                                        if (decCurrentExchangeRateId == 0)
                                        {
                                            CurrencyBll BllCurrency = new CurrencyBll();
                                            CurrencyInfo infoCurrency = new CurrencyInfo();
                                            infoCurrency = BllCurrency.CurrencyView(infoExchangeRate.CurrencyId);
                                            dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].Value = decCurrentExchangeRateId;

                                            Messages.InformationMessage("Set ExchangeRate for "+infoCurrency.CurrencyName);

                                        }
                                        else
                                        {
                                            dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].Value = decCurrentExchangeRateId;
                                        }
                                    }
                                    else
                                    {
                                        dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].Value = 1m;
                                    }
                                    dgvPartyBalance.CurrentRow.Cells["dgvtxtInvoiceNo"].Value = listObj[0].Rows[inD]["invoiceNo"].ToString();
                                }
                            }
                            dgvPartyBalance.CurrentRow.Cells["dgvtxtAmount"].Value = null;
                            dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].ReadOnly = true;
                        }
                        //to make voucherno,pendingamount,invoiceno,currency as null when vouchertype is selected as empty
                        else
                        {
                            dgvPartyBalance.CurrentRow.Cells["dgvtxtVoucherNo"].Value = null;
                            dgvPartyBalance.CurrentRow.Cells["dgvtxtPending"].Value = null;
                            dgvPartyBalance.CurrentRow.Cells["dgvtxtAmount"].Value = null;
                            dgvPartyBalance.CurrentRow.Cells["dgvtxtInvoiceNo"].Value = null;
                            dgvPartyBalance.CurrentRow.Cells["dgvcmbCurrency"].Value = null;
                            SettingsBll BllSettings = new SettingsBll();
                            if (BllSettings.SettingsStatusCheck("MultiCurrency") == "Yes")
                            {
                                dgvcmbCurrency.ReadOnly = false;
                            }
                            else
                            {
                                dgvcmbCurrency.ReadOnly = true;

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PB:16" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to call frmPaymentVoucher form to set amount for sundry creditors or sundry debtors
 /// </summary>
 /// <param name="frmPaymentVoucher"></param>
 /// <param name="decId"></param>
 /// <param name="dtblPartyBalance"></param>
 /// <param name="decPaymentVoucherTypeId"></param>
 /// <param name="strVoucherNo"></param>
 /// <param name="date"></param>
 /// <param name="arrlstOfDeletedPartyBalanceRow"></param>
 public void CallFromPaymentVoucher(frmPaymentVoucher frmPaymentVoucher, decimal decId, DataTable dtblPartyBalance, decimal decPaymentVoucherTypeId, string strVoucherNo, DateTime date, ArrayList arrlstOfDeletedPartyBalanceRow)
 {
     try
     {
         frmPaymentVoucher.Enabled = false;
         decVoucherTypeId = decPaymentVoucherTypeId;
         this.strVoucherNo = strVoucherNo;
         strDebitOrCredit = "Dr";
         decLedgerId = decId;
         this.dtblPartyBalance = dtblPartyBalance;
         dtmVoucherDate = date;
         base.Show();
         this.frmPaymentVoucherObj = frmPaymentVoucher;
         frmPaymentVoucherObj.Enabled = false;
         this.arrlstOfDeletedPartyBalanceRow = arrlstOfDeletedPartyBalanceRow;
         int inTableRowCount = dtblPartyBalance.Rows.Count;
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         PartyBalanceInfo InfoPartyBalance = new PartyBalanceInfo();
         //at the time of updation and at the time of loading frmPartyBalance when already entries are entered
         List<DataTable> listObj = new List<DataTable>();
         if (inTableRowCount > 0)
         {
             int inK = 0;
             for (int inI = 0; inI < inTableRowCount; inI++)
             {
                 if (decLedgerId == Convert.ToDecimal(dtblPartyBalance.Rows[inI]["LedgerId"].ToString()))
                 {
                     if (strDebitOrCredit == dtblPartyBalance.Rows[inI]["DebitOrCredit"].ToString())
                     {
                         dgvPartyBalance.Rows.Add();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value = dtblPartyBalance.Rows[inI]["ReferenceType"].ToString();
                         if (dgvPartyBalance.Rows[inK].Cells["dgvcmbReference"].Value.ToString() == "Against")
                         {
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].ReadOnly = false;
                             listObj = BllPartyBalance.PartyBalanceComboViewByLedgerId(decLedgerId, strDebitOrCredit, decVoucherTypeId, strVoucherNo);
                             DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbVoucherType"].Index, dgvPartyBalance.CurrentRow.Index - 1];
                             dgvccVoucherType.DataSource = listObj[0];
                             dgvccVoucherType.ValueMember = "value";
                             dgvccVoucherType.DisplayMember = "display";
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherTypeId"].ToString() + "_" + dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtVoucherNo"].Value = dtblPartyBalance.Rows[inI]["AgainstVoucherNo"].ToString();
                             dgvPartyBalance.Rows[inK].Cells["dgvtxtInvoiceNo"].Value = dtblPartyBalance.Rows[inI]["AgainstInvoiceNo"].ToString();
                             if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value != null && dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() != string.Empty)
                             {
                                 for (int inD = 0; inD < listObj[0].Rows.Count; inD++)
                                 {
                                     if (dgvPartyBalance.Rows[inK].Cells["dgvcmbVoucherType"].Value.ToString() == listObj[0].Rows[inD]["value"].ToString())
                                     {
                                         dgvPartyBalance.Rows[inK].Cells["dgvtxtpending"].Value = Math.Round(Convert.ToDecimal(listObj[0].Rows[inD]["balance"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                         break;
                                     }
                                 }
                             }
                             dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].ReadOnly = true;
                         }
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtAmount"].Value = Math.Round(Convert.ToDecimal(dtblPartyBalance.Rows[inI]["Amount"].ToString()), Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces)).ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtblPartyBalance.Rows[inI]["CurrencyId"].ToString());
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtCrDr"].Value = strDebitOrCredit;
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtPartyBalanceId"].Value = dtblPartyBalance.Rows[inI]["partyBalanceId"].ToString();
                         dgvPartyBalance.Rows[inK].Cells["dgvtxtOldExchangeRateId"].Value = dtblPartyBalance.Rows[inI]["OldExchangeRate"].ToString();
                         inK++;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:1" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Datagridview cell begin edit event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvPartyBalance_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
 {
     try
     {
         List<DataTable> listObj = new List<DataTable>();
         //DataTable dtbl1 = new DataTable();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         if (dgvPartyBalance.CurrentRow != null)
         {
             if (dgvPartyBalance.CurrentCell.ColumnIndex == dgvPartyBalance.Columns["dgvcmbVoucherType"].Index)
             {
                 if (dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value != null)//|| dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value.ToString() != string.Empty)
                 {
                     if (dgvPartyBalance.CurrentRow.Cells["dgvcmbReference"].Value.ToString() == "Against")
                     {
                         listObj = BllPartyBalance.PartyBalanceComboViewByLedgerId(decLedgerId, strDebitOrCredit, decVoucherTypeId, strVoucherNo);
                         DataRow dr = listObj[0].NewRow();
                         dr[0] = string.Empty;
                         dr[1] = 0;
                         dr[2] = string.Empty;
                         dr[3] = 0;
                         listObj[0].Rows.InsertAt(dr, 0);
                         if (dgvPartyBalance.RowCount > 2)
                         {
                             int inGridRowCount = dgvPartyBalance.RowCount;
                             for (int inI = 0; inI < inGridRowCount - 1; inI++)
                             {
                                 if (inI != e.RowIndex)
                                 {
                                     if (dgvPartyBalance.Rows[inI].Cells["dgvcmbReference"].Value != null)
                                     {
                                         if (dgvPartyBalance.Rows[inI].Cells["dgvcmbReference"].Value.ToString() == "Against")
                                         {
                                             int inTableRowcount = listObj[0].Rows.Count;
                                             for (int inJ = 0; inJ < inTableRowcount; inJ++)
                                             {
                                                 if (dgvPartyBalance.Rows[inI].Cells["dgvcmbVoucherType"].Value != null && dgvPartyBalance.Rows[inI].Cells["dgvcmbVoucherType"].Value.ToString() != string.Empty)
                                                 {
                                                     if (listObj[0].Rows[inJ]["Value"].ToString() == dgvPartyBalance.Rows[inI].Cells["dgvcmbVoucherType"].Value.ToString())
                                                     {
                                                         listObj[0].Rows.RemoveAt(inJ);
                                                         break;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbVoucherType"].Index, e.RowIndex];
                         dgvccVoucherType.DataSource = listObj[0];
                         dgvccVoucherType.ValueMember = "Value";
                         dgvccVoucherType.DisplayMember = "Display";
                     }
                 }
             }
             //To remove new or OnAccount from the reference combo when a new is selected
             else if (dgvPartyBalance.CurrentCell.ColumnIndex == dgvPartyBalance.Columns["dgvcmbReference"].Index)//to remove new from combobox when new is already selected
             {
                 if (dgvPartyBalance.RowCount > 1)
                 {
                     int inGridRowCount = dgvPartyBalance.RowCount;
                     for (int inI = 0; inI < inGridRowCount - 1; inI++)
                     {
                         //
                         if (inI != e.RowIndex)
                         {
                             if (dgvPartyBalance.Rows[inI].Cells["dgvcmbReference"].Value != null)
                             {
                                 if (dgvPartyBalance.Rows[inI].Cells["dgvcmbReference"].Value.ToString() == "New")
                                 {
                                     DataGridViewComboBoxCell dgvccReference = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbReference"].Index, e.RowIndex];
                                     dgvccReference.Items.Remove("New");
                                     break;
                                 }
                                 else
                                 {
                                     DataGridViewComboBoxCell dgvccReference = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbReference"].Index, e.RowIndex];
                                     if (!dgvccReference.Items.Contains("New"))
                                     {
                                         dgvccReference.Items.Add("New");
                                     }
                                 }
                             }
                         }
                     }
                     //
                     for (int inI = 0; inI < inGridRowCount - 1; inI++)
                     {
                         if (inI != e.RowIndex)
                         {
                             if (dgvPartyBalance.Rows[inI].Cells["dgvcmbReference"].Value != null)
                             {
                                 if (dgvPartyBalance.Rows[inI].Cells["dgvcmbReference"].Value.ToString() == "OnAccount")
                                 {
                                     DataGridViewComboBoxCell dgvccReference = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbReference"].Index, e.RowIndex];
                                     dgvccReference.Items.Remove("OnAccount");
                                     break;
                                 }
                                 else
                                 {
                                     DataGridViewComboBoxCell dgvccReference = (DataGridViewComboBoxCell)dgvPartyBalance[dgvPartyBalance.Columns["dgvcmbReference"].Index, e.RowIndex];
                                     if (!dgvccReference.Items.Contains("OnAccount"))
                                     {
                                         dgvccReference.Items.Add("OnAccount");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PB:25" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }