0

i'm new in vb and can't solve this problem of mine. I have this column from datagridview mark with red box:

enter image description here

And from the above image i want an output like this:

Team Edna - Esca, Adarayan, Dianne, //first shout
Team Edna - Esca, Bacalla, Catherine //2nd shout and so on..
Team Aennah, Aquino, Juan Benigno //3rd shout
Team Aennah, Aguila, Mailebeth //4rth shout and so on..

I already had the code that code detech if the string is starting with "TEAM" it just the discrepancy in the wanted output. Here's my code so far:

 For i As Integer = 1 To Me.DataGridView1.Rows.Count
            For Each row As DataGridViewRow In DataGridView1.Rows
                If Not row.IsNewRow Then
                    If InStr(row.Cells(0).Value.ToString.ToUpper, UCase(Trim("TEAM"))) <> 0 Then
                        team = row.Cells(0).Value.ToString.ToUpper
                        MessageBox.Show(team)
                        teamMembers = Me.DataGridView1.Rows(i).Cells(0).Value.ToString()
                        MessageBox.Show(team + ", " + teamMembers)
                    End If
                End If
            Next
        Next

And the output of this was:

Team Edna - Esca, Adarayan, Dianne
Team Aennah, Adarayan, Dianne
Team Edna, Bacalla, Catherine
Team Aennah, Bacalla, Catherine //so on..

Please help my guys.

18
  • I'm lost as to what you are asking here, also you have some things going on I'm not sure what team, team members or Monday does. Could you show the grid and how the data is in it and then how you want it. Commented Jan 31, 2014 at 3:58
  • Sorry, i already updated the code above. Team members are the list of members per team there. Commented Jan 31, 2014 at 4:00
  • Still doesn't make sense, please provide a screenshot of some sort of how the data is in the grid, than I can help you. Commented Jan 31, 2014 at 4:10
  • The screenshot is already there @MrCoDeXeR. Hope you would help me. Commented Jan 31, 2014 at 4:14
  • 1
    Or I should say you want all the first team and then the second to a message box right? Commented Jan 31, 2014 at 4:30

2 Answers 2

2

try this.. : replace your code ,

 Dim team, groups, teamMembers As String
        Dim _counter As Integer = 0

        For _xdtRow As Integer = 0 To DataGridView1.Rows.Count - 1

            If DataGridView1.Rows(_xdtRow).Cells(0).Value.ToString.Contains("Team") = True Then

                team = DataGridView1.Rows(_xdtRow).Cells(0).Value.ToString

                '_counter = _xdtRow

                For _xrow As Integer = (_xdtRow + 1) To DataGridView1.Rows.Count - 1

                    _counter += 1

                    If DataGridView1.Rows(_xrow).Cells(0).Value.ToString.Contains("Team") = True Then
                        Exit For
                    Else
                        teamMembers += DataGridView1.Rows(_xrow).Cells(0).Value.ToString & ","
                    End If

                Next

                _xdtRow = _counter

                groups += team & " - " & teamMembers & vbNewLine & vbNewLine

                'MsgBox(groups)

                team = Nothing
                teamMembers = Nothing

            End If
        Next

         Dim _perGrp As String()
    _perGrp = groups.Split(New Char() {"_"c})

    For Each perGrp As String In _perGrp
        MsgBox(perGrp)
    Next

OUTPUT:

enter image description here

HTH.. :)

Sign up to request clarification or add additional context in comments.

Comments

2

This example ALSO includes you other items as well... you have arrays that you can play around with or send it to messagebox, richtextbox or what ever you want with it...

 Private Sub btnOutput_Click(sender As Object, e As EventArgs) Handles btnOutput.Click
    Dim arrTeamOne As New ArrayList
    Dim arrTeamTwo As New ArrayList
    Dim strMembers As New StringBuilder
    Dim blnTeamOne As Boolean = False

    For i As Integer = 0 To dgvMembers.Rows.Count - 1
        If Not (dgvMembers.Rows(i).Index = 0) Then
            If dgvMembers.Rows(i).Cells(0).Value.ToString.Contains("Team Edna - Esca") Then
                Continue For
            Else
                If Not dgvMembers.Rows(i).Cells(0).Value.ToString.Contains("Team Aennah") Then
                    If Not blnTeamOne Then
                        arrTeamOne.Add("Team Edna - Esca, " & dgvMembers.Rows(i).Cells(0).Value.ToString & ", " & dgvMembers.Rows(i).Cells(1).Value.ToString & ", " & dgvMembers.Rows(i).Cells(2).Value.ToString)
                    Else
                        arrTeamTwo.Add("Team Aennah, " & dgvMembers.Rows(i).Cells(0).Value.ToString & ", " & dgvMembers.Rows(i).Cells(1).Value.ToString & ", " & dgvMembers.Rows(i).Cells(2).Value.ToString)
                    End If
                Else
                    If dgvMembers.Rows(i).Cells(0).Value.ToString.Contains("Team Aennah") Then
                        blnTeamOne = True
                        Continue For
                    End If
                End If
            End If
        End If
      Next

    For Each arr As String In arrTeamOne
        strMembers.AppendLine(arr.ToString)
    Next
    For Each arr As String In arrTeamTwo
        strMembers.AppendLine(arr.ToString)
    Next
    Messagebox.Show(strMembers.ToString)
End Sub

Here's what the output looks like...

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.