-
Oct 19th, 2014, 08:56 PM
#1
Thread Starter
Registered User
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
-
Oct 20th, 2014, 09:18 AM
#2
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
-
Oct 20th, 2014, 09:56 AM
#3
Hyperactive Member
Re: selecting datagridview rows
vb .net Code:
DataGridView.CurrentRow.Cells(CellIndex).Value.ToString
If you wanted the whole row, something like this:
vb .net Code:
For i = 0 to DataGridView.ColumnCount - 1 msgbox(DataGridView.CurrentRow.Cells(i).Value.ToString) Next
-
Oct 20th, 2014, 08:06 PM
#4
Thread Starter
Registered User
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
-
Oct 21st, 2014, 06:23 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|