-
Oct 3rd, 2022, 08:16 AM
#1
Thread Starter
Lively Member
make more beautiful
The code works as it should, but I think you can make it shorter and cleaner. Can someone please help me?
Code:
For i = 0 To dgvplugins.Rows.Count - 1
Try
If dgvplugins.Rows(i).Cells(1).Value = dgvplugins.Rows(i).Cells(2).Value Then
dgvplugins.Rows(i).Cells(1).Style.ForeColor = System.Drawing.Color.LightGreen
dgvplugins.Rows(i).Cells(4) = New DataGridViewImageCell With {.Value = My.Resources.ok_16green}
Else
dgvplugins.Rows(i).Cells(1).Style.ForeColor = System.Drawing.Color.DeepPink
dgvplugins.Rows(i).Cells(4) = New DataGridViewImageCell With {.Value = My.Resources.warningrund_16}
If dgvplugins.Rows(i).Cells(3).Value = "cf" Then
dgvplugins.Rows(i).Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.codefling}
ElseIf dgvplugins.Rows(i).Cells(3).Value = "cc" Then
dgvplugins.Rows(i).Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.chaoscode}
ElseIf dgvplugins.Rows(i).Cells(3).Value = "ld" Then
dgvplugins.Rows(i).Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.lonedesign}
ElseIf dgvplugins.Rows(i).Cells(3).Value = "mv" Then
dgvplugins.Rows(i).Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.myvector}
ElseIf dgvplugins.Rows(i).Cells(3).Value = "um" Then
dgvplugins.Rows(i).Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.umod}
dgvplugins.Rows(i).Cells(6) = New DataGridViewImageCell With {.Value = My.Resources.arrow_158_16}
End If
End If
Catch ex As Exception
End Try
Next
-
Oct 3rd, 2022, 08:37 AM
#2
Re: make more beautiful
How about you explain what you're trying to achieve, instead of making us all work it out from the code?
-
Oct 3rd, 2022, 09:00 AM
#3
Thread Starter
Lively Member
Re: make more beautiful
Thought that was obvious because the code is so bad.
Don't know what there is to explain.
I add a new row to the DataGridView.
Then in the added row I want to compare cell 1 and 2.
If cell 1 and 2 are the same, then change the ForeColor in cell 1 to LightGreen and insert an image in cell 4
If cell 1 and 2 are not the same, then change the ForeColor in cell 1 to DeepPink and insert an image in cell 4 and 6.
Then in the same row check cell 3 for a text.
If e.g. in cell 3 cf is written, then in cell 5 the image codefling should be added.
The code works, but I think you can make it shorter/cleaner/better.
Option Strict Off should be like this for now.
-
Oct 3rd, 2022, 09:43 AM
#4
Re: make more beautiful
The code can be shortened using With .. End With blocks
And by replacing the long If .. ElseIF .. block
Code:
' Just a small part
With dgvplugins.Rows(i)
Select Case .Cells(3).Value
case "cf": .Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.codefling}
case "cc": .Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.chaoscode}
case "ld": .Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.lonedesign}
case "mv": .Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.myvector}
case "um"
.Cells(5) = New DataGridViewImageCell With {.Value = My.Resources.umod}
.Cells(6) = New DataGridViewImageCell With {.Value = My.Resources.arrow_158_16}
End Select
End With
-
Oct 3rd, 2022, 10:48 AM
#5
Re: make more beautiful
Moderator Actions - Moved thread to Code It Better forum.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|