Results 1 to 3 of 3

Thread: How To Fill Datagridview Colomn From Another Datagridview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Location
    INDONESIA - BALI
    Posts
    27

    Question 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:

    Name:  Baru Mahasiswa.JPG
Views: 1110
Size:  50.2 KB

    and datagridview2:

    Name:  Baru Skor Mahasiswa.JPG
Views: 1032
Size:  35.5 KB

    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..

  2. #2
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Location
    INDONESIA - BALI
    Posts
    27

    Resolved 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 :

    dgvDataAwalMahasiswa = Datagridview1 [Where Data From]
    dgvMetodePanitiaMahasiswa = Datagridview2 [Destination Of Data]
    To Do This, Datagridview1 and Datagridview2 Must Have Same Rows!

    Thanks Ian Ryder

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