• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    C#winform實現在datagridview中輸入數據并計算

    在winform開辟過程中,需要對datagridview中查詢出來的數據進行計較,也就是說,我們在此中一個欄位中輸入數據,將會使指心猿意馬的單位格數據也發生轉變,下面,我們就一路來看看,怎么實現輸入重量,按照原有的單價和數目算出總金額。

    東西/原料

    • 電腦 VS軟件

    方式/步調

    1. 1

      在winform中把要實現的功能界面先做好,這里,我但愿經由過程輸入重量來計較出總金額。

    2. 2

      編寫根基數據抓取的代碼

         private void textBox1_KeyDown(object sender, KeyEventArgs e)

              {

                  if (e.KeyCode == Keys.Enter && textBox1.Text != "")

                  {

                      show_data(dataGridView1);

                      //dataGridView1.AllowUserToAddRows = false;//關閉dataGridview中最後一個空白行。

                  }

                  else

                  {

                  }

              }

    3. 3

      用datagridview中單位格編纂完當作的事務去做實現數據的變動和后續動作。

    4. 4

      編寫單位格編纂完當作后的事務代碼

            private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)

              {

                  if (dataGridView1.Rows.Count > 1)

                  {

                      for (int i = 0; i < dataGridView1.Rows.Count; i++)

                      {

                          if (int.Parse(dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString()) > 0)

                          {

                              float m = float.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString());

                              float l = float.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString());

                              int n = int.Parse(this.dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString());

                              string a = ((m * n)+(l*n)).ToString();

                              this.dataGridView1.Rows[e.RowIndex].Cells[11].Value = a;

                          }

                      }

                  }

                  else

                  {

                  }

              }

    5. 5

      注重重點行號必然是要用 e.RowIndex來暗示,如許才會輪回到最后一行,不然會報錯。

    6. 6

      測試輸入重量按照設心猿意馬的公式顯示總金額,目標達到。

    • 發表于 2018-04-20 00:00
    • 閱讀 ( 1962 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    admin
    admin

    0 篇文章

    作家榜 ?

    1. xiaonan123 189 文章
    2. 湯依妹兒 97 文章
    3. luogf229 46 文章
    4. jy02406749 45 文章
    5. 小凡 34 文章
    6. Daisy萌 32 文章
    7. 我的QQ3117863681 24 文章
    8. 華志健 23 文章

    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆