2 Attachment(s)
How To Fill Datagridview Colomn From Another Datagridview
Morning All..
I need your help for my problem.
I want to fill my datagridview from another datagridview.
I have datagridview1 with data looks like the picture below:
Attachment 107369
and datagridview2:
Attachment 107371
Do you see the yellow colomn in datagridview1 and datagridview2?
I want make If Else Statement from datagridview1 for fill datagridview2:
The algorithm look like the code below :
Code:
If IPK[Datagridview1] > 3.75 Then IPK[Datagridview2] = 100
Elseif IPK[Datagridview1] > 3.50 AND < 3.75 Then IPK[Datagridview2] = 90
Elseif IPK[Datagridview1] > 3.25 AND < 3.5 Then IPK[Datagridview2] = 80
Elseif IPK[Datagridview1] > 3.00 AND < 3.25 Then IPK[Datagridview2] = 70
Elseif IPK[Datagridview1] > 2.75 AND < 3.0 Then IPK[Datagridview2] = 60
Elseif IPK[Datagridview1] > 2.50 AND < 2.75 Then IPK[Datagridview2] = 50
Elseif IPK[Datagridview1] < 2.50 Then IPK[Datagridview2] = 0
End If
How can i do that? Please teach me.. :wave: :wave:
Re: How To Fill Datagridview Colomn From Another Datagridview
Hi,
You have shown some pseudo code there but what have you actually tried so far? You would be better off doing this with the underlying DataSource otherwise you need to follow along the lines of something like this:-
1) Create a For Loop to iterate through the Rows of your First DataGridView to get each row. Make sure you ignore the NewRow at the end of the DataGridView.
2) For each Row in the above For loop you need to find the corresponding Row in the Second DataGridView. This can be done with another For Loop or with LINQ, whichever you prefer.
3) Once you have found the corresponding row in the second DataGridView you need to use your Case Statement to set the Value of the necessary Cell in the Second DataGridView.
That's it and give it a try.
Hope that helps.
Cheers,
Ian
Re: How To Fill Datagridview Colomn From Another Datagridview
I have been found my solution!
This is the code :
Code:
For i As Integer = 0 To dgvDataAwalMahasiswa.Rows.Count - 1
If dgvDataAwalMahasiswa.Rows(i).Cells(3).Value >= 3.75 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 100
ElseIf dgvDataAwalMahasiswa.Rows(i).Cells(3).Value >= 3.5 And dgvDataAwalMahasiswa.Rows(i).Cells(3).Value < 3.75 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 90
ElseIf dgvDataAwalMahasiswa.Rows(i).Cells(3).Value >= 3.25 And dgvDataAwalMahasiswa.Rows(i).Cells(3).Value < 3.5 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 80
ElseIf dgvDataAwalMahasiswa.Rows(i).Cells(3).Value >= 3 And dgvDataAwalMahasiswa.Rows(i).Cells(3).Value < 3.25 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 70
ElseIf dgvDataAwalMahasiswa.Rows(i).Cells(3).Value >= 2.75 And dgvDataAwalMahasiswa.Rows(i).Cells(3).Value < 3 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 60
ElseIf dgvDataAwalMahasiswa.Rows(i).Cells(3).Value >= 2.5 And dgvDataAwalMahasiswa.Rows(i).Cells(3).Value < 2.75 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 50
ElseIf dgvDataAwalMahasiswa.Rows(i).Cells(3).Value < 2.5 Then
dgvMetodePanitiaMahasiswa.Rows(i).Cells(3).Value = 0
End If
Next
Note :
Quote:
dgvDataAwalMahasiswa = Datagridview1 [Where Data From]
dgvMetodePanitiaMahasiswa = Datagridview2 [Destination Of Data]
Quote:
To Do This, Datagridview1 and Datagridview2 Must Have Same Rows!
Thanks Ian Ryder :thumb: