Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Creveti

Sare siguranta cand pornesc masin...

Verificare structura de rezistent...

Masina nr 2 - 90% oras, benzina, ...
 Tratament ortodontic

Passat B5 2000, fum

navigația auto nu porneș...

Demontare plastic hayon Seat Ateca
 Placa de baza Samsung Galaxy M21

Casca scuter electric + suport pi...

Inmatriculare temporara Suedia

Abonament sala
 CSS - E posibil sa ignori opacita...

Intrebare Facebook

RMN pentru claustrofobi

Constructie parapet
 

Suma unei coloane DataGrid intr-un textbox

- - - - -
  • Please log in to reply
5 replies to this topic

#1
Sargon

Sargon

    Junior Member

  • Grup: Members
  • Posts: 119
  • Înscris: 20.09.2007
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...

#2
dani.user

dani.user

    Guru Member

  • Grup: Senior Members
  • Posts: 29,385
  • Înscris: 24.02.2007
http://stackoverflow...rently-onscreen

#3
Sargon

Sargon

    Junior Member

  • Grup: Members
  • Posts: 119
  • Înscris: 20.09.2007
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
Sargon

Sargon

    Junior Member

  • Grup: Members
  • Posts: 119
  • Înscris: 20.09.2007
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
neagu_laurentiu

neagu_laurentiu

    Guru Member

  • Grup: Senior Members
  • Posts: 39,897
  • Înscris: 30.07.2003

View PostSargon, on 01 septembrie 2012 - 07:49, said:

sum += Me.DataGridView1.Rows(i).Cells(5).Value.ToString()
Stringurile pot face o suma ?!

Edited by neagu_laurentiu, 01 September 2012 - 07:52.


#6
Sargon

Sargon

    Junior Member

  • Grup: Members
  • Posts: 119
  • Înscris: 20.09.2007
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

Chirurgia cranio-cerebrală minim invazivă Chirurgia cranio-cerebrală minim invazivă

Tehnicile minim invazive impun utilizarea unei tehnologii ultramoderne.

Endoscoapele operatorii de diverse tipuri, microscopul operator dedicat, neuronavigația, neuroelectrofiziologia, tehnicile avansate de anestezie, chirurgia cu pacientul treaz reprezintă armamentarium fără de care neurochirurgia prin "gaura cheii" nu ar fi posibilă. Folosind tehnicile de mai sus, tratăm un spectru larg de patologii cranio-cerebrale.

www.neurohope.ro

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate