Suma unei coloane DataGrid intr-un textbox
Last Updated: Sep 01 2012 09:11, Started by
Sargon
, Aug 31 2012 18:57
·
0

#1
Posted 31 August 2012 - 18:57

Salutare,
In VB 2010, am un form cu un combobox si un datagridview. In datagridview sint selectate informatiile care sint corespund informatiei selectate de combobox. Trebuie sa insumez datele dintr-o coloana astfel filtrata (prin intermediul combobox-ului), iar suma rezultata sa fie afisata intr-un textbox mai jos... Am reusit filtratrea datagridview cu ajutorul combobox-ului, dar nu reusesc sa insumez coloana filtrata... |
#3
Posted 31 August 2012 - 20:33

Dani, iti multumesc pentru link , dar pentru mine C# este un fel de limba japoneza...nu ma descurc prea bine nici cu VB...
Cred ca in VB ar fi cam asa: Public Sub GetVisibleCells(dgv As DataGridView) Dim vivibleRowsCount as dgv.DisplayedRowCount(True) Dim firstDisplayedRowIndex as dgv.FirstDisplayedCell.RowIndex Dim lastvibileRowIndex as (firstDisplayedRowIndex + vivibleRowsCount) - 1 For rowIndex As Integer = firstDisplayedRowIndex To lastvibileRowIndex Dim cells = dgv.Rows(rowIndex).Cells For Each cell As DataGridViewCell In cells ' This cell is visible... ' Your code goes here... If cell.Displayed Then End If Next Next End Sub Da' tot nu vad cum mi-ar aduna valorile dintr-o anumita coloana (de exemplu , coloana "vanzari"). Edited by Sargon, 31 August 2012 - 20:35. |
#4
Posted 01 September 2012 - 07:49

Hai ca am reusit cu urmatorul cod:
Dim sum As Integer = 0 For i = 0 To Me.DataGridView1.RowCount - 1 If Not DataGridView1.Rows(i).Cells(5).Value Is Nothing Then sum += Me.DataGridView1.Rows(i).Cells(5).Value.ToString() End If Next Me.TextBox3.Text = sum |
#5
Posted 01 September 2012 - 07:52

#6
Posted 01 September 2012 - 09:11

Nu stiu eu cum sta treaba cu "String-urile", dar Iata intreg codul... si functioneaza bine:
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'VBTestDataSet.Customer' table. You can move, or remove it, as needed. Me.CustomerTableAdapter.Fill(Me.VBTestDataSet.Customer) 'TODO: This line of code loads data into the 'VBTestDataSet.Invoices' table. You can move, or remove it, as needed. Me.InvoicesTableAdapter.Fill(Me.VBTestDataSet.Invoices) Me.DataGridView1.Visible = False End Sub Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged Me.InvoicesBindingSource.Filter = "CID ='" & ComboBox1.SelectedValue & "'" Me.DataGridView1.Visible = True Dim sum As Integer = 0 For i = 0 To Me.DataGridView1.RowCount - 1 If Not DataGridView1.Rows(i).Cells(5).Value Is Nothing Then sum += Me.DataGridView1.Rows(i).Cells(5).Value.ToString() End If Next Me.TextBox3.Text = sum End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Beep() Form2.Show() End Sub End Class Edited by Sargon, 01 September 2012 - 09:11. |
Anunturi
Bun venit pe Forumul Softpedia!
▶ 0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users