Results 1 to 5 of 5

Thread: [RESOLVED] Rowcount particular value

  1. #1

    Thread Starter
    Junior Member feroguz's Avatar
    Join Date
    Aug 2013
    Posts
    22

    Resolved [RESOLVED] Rowcount particular value

    Hi vbforum users!

    I need to rowcount in datagridview with a particular value.
    My column "6" have the value that find, I try with the following code:

    Code:
      Dim apc As Decimal = 0
    For x As Integer = 0 To DataGridView3.RowCount - 1
                If DataGridView3.Rows(x).Cells(6).Value = "AP" Then
                    apc = DataGridView3.Rows(x).Cells(6).Value.ToString.Count
                End If
    
            Next
    textbox1.text=apc
    any help, as welcome!!
    Best Regards!!

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: Rowcount particular value

    Are you trying to get the sum of the values in column 6, or just the count of the number of rows that have the given value?

    If the former, then the line above would look like:
    vb Code:
    1. apc += DataGridView3.Rows(x).Cells(6).Value

    If the latter, then you would simply say:
    vb Code:
    1. apc += 1
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  3. #3

    Thread Starter
    Junior Member feroguz's Avatar
    Join Date
    Aug 2013
    Posts
    22

    Re: Rowcount particular value

    Great Dolot! Best Regards!

    Code:
     For x = 0 To DataGridView3.Rows.Count - 1
                If DataGridView3.Rows(x).Cells(6).Value = "AP" Then
                    count += 1
                End If
            Next

  4. #4
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: Rowcount particular value

    How exactly is the datagridview being populated? Is there a datatable attached to it, or is it just user input?
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  5. #5

    Thread Starter
    Junior Member feroguz's Avatar
    Join Date
    Aug 2013
    Posts
    22

    Re: Rowcount particular value

    Hi Sr!

    Only populate the textbox

    Code:
     For x = 0 To DataGridView3.Rows.Count - 1
                If DataGridView3.Rows(x).Cells(6).Value = "AP" Then
                    count += 1
                End If
            Next
    textbox1.text=count

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width