Results 1 to 5 of 5

Thread: selecting datagridview rows

  1. #1

    Thread Starter
    Registered User
    Join Date
    Oct 2014
    Posts
    4

    selecting datagridview rows

    Datagridview1

    DUE_DATE|OPB
    10/20/14|1000
    11/20/14|2000
    12/20/14|3000
    1/20/15|4000
    2/20/15|5000
    3/20/15|6000

    Datagridview2

    MONTH_APPLIED|OPB
    _____________|1500
    _____________|3000
    _____________|4500
    _____________|6000

    I need to select the DUE_DATE from Datagridview1 and put it in MONTH_APPLIED to Datagridview2

    the output should be like this

    MONTH_APPLIED|OPB
    10/20/14|1500
    12/20/14|3000
    1/20/15|4500
    3/20/15|6000

    Code:
    If DataGridView2.Rows(0).Cells("OPB").Value > DataGridView1.Rows(0).Cells("OPB").Value Then
    'what code should i put to get the output
                ElseIf DataGridView2.Rows(0).Cells("OPB").Value < DataGridView1.Rows(0).Cells("OPB").Value Then
    'what code should i put to get the output
                End If

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: selecting datagridview rows

    Hello, and welcome to the forums!

    Before answering your question, can I ask where this data is coming from? Is it being entered by hand or read from a database or what exactly?
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  3. #3
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Re: selecting datagridview rows

    vb .net Code:
    1. DataGridView.CurrentRow.Cells(CellIndex).Value.ToString

    If you wanted the whole row, something like this:

    vb .net Code:
    1. For i = 0 to DataGridView.ColumnCount - 1
    2. msgbox(DataGridView.CurrentRow.Cells(i).Value.ToString)
    3. Next

  4. #4

    Thread Starter
    Registered User
    Join Date
    Oct 2014
    Posts
    4

    Re: selecting datagridview rows

    dolot

    datagridview2 is from a database
    datagridview1 is manually computed on my code.

    im getting the DUE_DATE in datagridview2 and inserting it in datagridview1 MONTH_APPLIED.

    using this code

    Code:
     DataGridView1.Rows(counter).Cells("MONTH_APPLIED").Value = (DataGridView2.Rows(counter).Cells("DUE_DATE").Value)
    which i get

    MONTH_APPLIED|OPB
    10/20/14|1500
    11/20/14|3000
    12/20/15|4500
    1/20/15|6000

  5. #5
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: selecting datagridview rows

    You don't really need to take the computed data and insert it into a datagridview1 - not if you're generating that data in code. I'm not sure exactly how you're creating the data in grid1, but if all grid is doing is acting as a temporary holding place for data, then you can probably do it another way.

    I'd try something like this:
    Code:
        Private Function GetDate(ByVal OPB As Integer) As Date
            'put the code in there that generates the month applied date from the OPB
        End Function
    Then populate the values for grid2 with something like this:
    Code:
            For Each row As DataGridViewRow In Me.DataGridView2.Rows
                row.Cells(0).Value = GetDate(row.Cells(1).Value)
            Next
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

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