2017-07-16 43 views
-1

私はVB i want to check the cells and set the value to text box移動平均法VB

で移動平均を行うために試してみたが、結果はある all the text box has the same value

私の最初のチェック値(penjualan /ブラン)の作り方

は、最初のテキストボックスにinputedさ 2番目のチェックボックス(penjualan/bulan)を2番目のテキストボックスに入力します。 ここに私のコードです

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick 
     If e.ColumnIndex = 5 Then 
      tb1.Text = DataGridView1.CurrentRow.Cells(3).Value 
      tb2.Text = DataGridView1.CurrentRow.Cells(3).Value 
      tb3.Text = DataGridView1.CurrentRow.Cells(3).Value 
     End If 
    End Sub 

ありがとうございます。

+0

[お問い合わせ]を読んで[ツアー]をご覧ください。あなたの質問に関係するすべての事実は疑問の余地があります。それを自分で解決する努力が必要です – Plutonix

答えて

0

cellClicked-eventが3つのテキストボックスをすべて同じ値である0,に上げるときはいつでも設定します。 もう1つの問題は、コードがTextboxのテキストを常に設定することです。チェックボックスがオンになっているかどうかはチェックされません。この列の任意のセルをクリックするたびに更新され、3つのボックスのテキストが現在選択されている行の値に更新されます。

ここには解決策があります。完璧ではありませんが、それを理解し、最適化しようとするべきですが、うまくいくはずです。

Public Class Form1 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     InitializeDgv() 
    End Sub 

    Private Sub InitializeDgv() 
     Dim row as String() = New String(){"2016",240} 
     DataGridView1.Rows.Add(row) 
     row = New String(){"2017",223} 
     DataGridView1.Rows.Add(row) 
     row = New String(){"2015",54} 
     DataGridView1.Rows.Add(row) 
    End Sub 

    Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged 
     if e.ColumnIndex=2 

      Dim checkedRows=(From dgv as DataGridViewRow in DataGridView1.Rows where dgv.Cells(2).Value=True select dgv).ToList() 
      Dim controlsList As new List(of TextBox) 
      controlsList.Add(TextBox1) 
      controlsList.Add(TextBox2) 
      controlsList.Add(TextBox3) 
      for Each item in controlsList 
       item.Text=String.Empty 
      Next 
      for i=0 to checkedRows.Count-1 
       controlsList(i).Text=checkedRows.Item(i).Cells(0).Value 
      Next 
     End If 
    End Sub 
End Class