Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have value in stringbuilder in richtextbox from datagridview. The value from Jan until present but the value is not as I expected. The result is :
Month : Jan

ProjectA 116
MEET 112, 96.55%
MISSED 4, 3.45%

ProjectB 4
MEET 3, 75.00%
MISSED 1, 25.00%

ProjectC 8
MEET 2, 25.00%
MISSED 6, 75.00%

etc

My expectation is :
Month : Jan

ProjectA 116
MEET 112, 96.55%
MISSED 4, 3.45%

ProjectB : 4
MEET : 2, 50.00%
MISSED : 2, 50.00%

ProjectC : 8
MEET : 3, 37.50%
MISSED : 5, 62.50%

I already check on the value in datagridview ( eg MEET / MISSED , Project ) , there is nothing wrong with that
This my syntax :
Dim DicAchievement, DicProject As New Dictionary(Of String, Integer)()
Dim cellValue As String = Nothing
Dim cellMeet As String = Nothing
Dim sb As New StringBuilder()
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If Not DataGridView1.Rows(i).IsNewRow Then
cellValue = Trim(DataGridView1("Project", i).Value.ToString())
If Not DicProject.ContainsKey(cellValue) Then
    DicProject.Add(cellValue, 1)
Else
    DicProject(cellValue) += 1
End If
End If
Next
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If Not DataGridView1.Rows(i).IsNewRow Then
cellValue = Trim(DataGridView1("Project", i).Value.ToString())
cellMeet = Trim(DataGridView1("Achievement", i).Value.ToString())
If cellMeet.Contains("MEET") Then
If Not cellMeet = vbNullString Then
If Not DicAchievement1.ContainsKey(cellValue) Then
DicAchievement1.Add(cellValue, 1)
Else
DicAchievement1(cellValue) += 1
End If
End If
End If
End If
Next

sb.AppendLine("Month : " & Me.CMonth.Text & vbNewLine)
Dim lineStrings = DicProject.Zip(DicAchievement1, _
Function(m, mt) String.Format("{0} : {1}" & vbNewLine & "MEET : {2}, {3}" & vbNewLine & "MISSED : {4}, {5}", _
    UCase(m.Key), m.Value, mt.Value, FormatPercent((mt.Value / m.Value), 2), m.Value - mt.Value, _
    FormatPercent((m.Value - mt.Value) / m.Value, 2), mt.Value))

For Each ls In lineStrings
sb.AppendLine(ls & vbNewLine)
Next
RichTextBox2.Text = sb.ToString

whether there is something wrong with my syntax ?
Please help......
Posted
Comments
Sergey Alexandrovich Kryukov 9-Apr-15 11:56am    
What makes you thinking that you have a StringBuilder object in DataGridView. Did you create a special cell type for that? Then why?
—SA
KukuhSP 9-Apr-15 12:13pm    
Not in Datagridview but in RichTextBox.I get the value of stringbuilder from DataGridView
Sergey Alexandrovich Kryukov 9-Apr-15 12:23pm    
In RichTextBox? How?
—SA
Maciej Los 9-Apr-15 13:26pm    
I think the problem described as: "the value is not as I expected" is not well formed...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900