0

項目DataGridView、説明、数量、レート、合計の列があります。私は 2 種類のアイテムを持っています。1 つのアイテムには vapasi == はい (vapasi は預金額の一種です) があり、別のアイテムには vapasi == いいえがあります。この計算された合計を、グリッドの後にある 'txtboxwithvapasi'、n 'txtboxwithoutvapasi' という 2 つのそれぞれのテキスト ボックスに表示したいと考えています。次のコードを実行しました。

private void grdPurchase_CellEndEdit_1(object sender, DataGridViewCellEventArgs e)
{
    try
    {
        try
        {
            string value = grdPurchase.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            if (e.ColumnIndex == 2)
            {
                int val = int.Parse(value);
                quantity = val;
            }
            if (e.ColumnIndex == 4)
            {
                float val = float.Parse(value);
                total = val;

                if (vapasi1 == "Yes")
                {
                    vtot += total; //vtot=0+10

                    txt_forvapasitotal.Text = vtot.ToString(); //10
                    float vapsitot =float.Parse(txt_forvapasitotal.Text);
                    float vapsicalculate = (vapsitot * a);
                    float tax = vapsicalculate / 100;
                    float with_vapasi = vtot + tax;
                    txt_withvapasi.Text =Convert.ToString(with_vapasi);
                }
                else
                {
                    nvtot = 0;

                    for (int i = 0; i < grdPurchase.Rows.Count; i++)
                    {
                        if (vapasi1 == "No")
                        {
                            if (grdPurchase.Rows[e.RowIndex].Cells[3].Selected == true)
                            {
                                nvtot += float.Parse(grdPurchase[4, i].EditedFormattedValue.ToString());
                                txt_withoutvapasitot.Text = nvtot.ToString();
                            }
                        }
                    }
                }
              txt_vapasiincludedtot.Text =(float.Parse(txt_withvapasi.Text) +float.Parse(txt_withoutvapasitot.Text)).ToString();
          }
          if (e.ColumnIndex == 1)
          {
              int val = int.Parse(value);
              materialid = val;
              string vapasi = "Select material_vapasi from tbl_material_master where active_flag=1 AND material_id =" + materialid + "";
              SqlCommand cmd = new SqlCommand(vapasi, con);
              sdr = cmd.ExecuteReader();
              if (sdr.HasRows)
              {
                  while (sdr.Read())
                  {
                      vapasi1 = sdr["material_vapasi"].ToString();
                  }
              }
           }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
        grdPurchase.Columns[3].ReadOnly = false;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message.ToString());
    }
}

問題は次のとおりです。-最初の行でvapasiを含むアイテムを選択し、2行目のvapasiを含まないアイテムを選択すると、正しく機能します.しかし、3行目のアイテムを選択すると、「txtboxwithoutvapasi」の3つのアイテムすべての合計差別化アイテム。

4

1 に答える 1

0

グリッドの各行でvapasiが「はい」または「いいえ」であることを追跡する必要がありますが、単一の変数を使用しています。この列をグリッドに追加できませんか(ユーザーに表示したくない場合は非表示の列として)?次に、合計を計算する必要があるときはいつでも、グリッド行を反復処理し、 vapasi1変数の代わりにvapasi列をチェックします。

于 2012-06-20T08:04:41.603 に答える