-
Nov 5th, 2019, 06:13 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Increment value by 1 from specified value
Hi,
In a DGV i want to select rows and then every row that is selected (checked) must be 're-numbered' from a specified value and onwards.
Meaning....
Say I have 5 rows selected then I specified where to start (in my code below I say start at 94) Then column 2 must look like this:
95
96
97
98
99
Code:
Dim lastRow As Integer = 94
For i = lastRow +1 To ?? (maybe I must count the number of checked rows?)
For Each checkedRow As DataGridViewRow In Me.TblRiskAssessmentDataGridView.Rows
Dim checked As Boolean = CType(checkedRow.Cells("Column1").Value, Boolean)
If checked Then
checkedRow.Cells(2).Value = i + 1
End If
Next
Next
thanks....
-
Nov 5th, 2019, 06:55 AM
#2
Re: Increment value by 1 from specified value
lastRow contains the value you want to use but you're not actually using it anywhere. As I have said more than once before, you should be working out the logic first and, if necessary, writing it down or typing it out. You can then compare the code you write to that algorithm to see whether it actually does what you want it to. You seem to have again written code without actually working out what that code is supposed to do. Each time you find a checked row, you need to put the desired value, i.e. lastRow, into that row and then you need to increment that value, i.e. lastRow.
You're still making the same mistakes as you have been for the last 2 and a half years and I can't really be bothered repeating myself any more. Looks like you will be rid of the garbage and the gold. I'm done.
-
Nov 5th, 2019, 08:29 AM
#3
Thread Starter
Frenzied Member
Re: Increment value by 1 from specified value
Looks like you will be rid of the garbage and the gold
Sorry if I hurt your feelings, John....
Maybe that is for the best. Because honestly I am actually too afraid to ask questions here because of your tantrums... Always moan and complain about everything where in actual fact you did not need to respond at all if the question is not to your high standards. It seems that there is this notion on vbforums that the person asking a question is always wrong, and the person choosing to answer is always right - and just by responding automatically gains the right to lambaste the person asking a question.
But as I said if I don't get a straight up answer......
PS:
Each time you find a checked row, you need to put the desired value, i.e. lastRow, into that row and then you need to increment that value, i.e. lastRow.
For what is worth you are wrong because every row will have the same value then...
Last edited by schoemr; Nov 5th, 2019 at 08:34 AM.
-
Nov 5th, 2019, 01:48 PM
#4
Re: Increment value by 1 from specified value
It looks like your approach is wrong, you don't need to know how many rows were checked, only the starting number.
Code:
Dim lastRow As Integer = 94
For Each checkedRow As DataGridViewRow In Me.TblRiskAssessmentDataGridView.Rows
Dim checked As Boolean = CType(checkedRow.Cells("Column1").Value, Boolean)
If checked Then
lastrow += 1
checkedRow.Cells(2).Value = lastrow
End If
Next
This code isn't tested
Last edited by wes4dbt; Nov 5th, 2019 at 06:07 PM.
-
Nov 6th, 2019, 12:59 AM
#5
Thread Starter
Frenzied Member
Re: Increment value by 1 from specified value
Originally Posted by wes4dbt
It looks like your approach is wrong, you don't need to know how many rows were checked, only the starting number.
Code:
Dim lastRow As Integer = 94
For Each checkedRow As DataGridViewRow In Me.TblRiskAssessmentDataGridView.Rows
Dim checked As Boolean = CType(checkedRow.Cells("Column1").Value, Boolean)
If checked Then
lastrow += 1
checkedRow.Cells(2).Value = lastrow
End If
Next
This code isn't tested
Hi Wes,
Thank you very much for this. It is working perfectly. Yesterday when I was trying to figure it out I actually reached this at some point:
Code:
checkedRow.Cells(2).Value = lastRow += 1
wrong, but I think close
This never occurred to me:
Code:
lastrow += 1
checkedRow.Cells(2).Value = lastrow
Thanks again...
-
Nov 6th, 2019, 06:56 AM
#6
Re: [RESOLVED] Increment value by 1 from specified value
It was probably closer than you think...
Code:
checkedRow.Cells(2).Value = lastRow += 1
Code:
checkedRow.Cells(2).Value = lastRow + 1
+= is an assignment and doesn't return a value. You could write...
Code:
Dim value as integer = 9
value += 1
Which is equivalent to...
Code:
Dim value as integer = 9
value = value + 1
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 6th, 2019, 09:48 AM
#7
Re: Increment value by 1 from specified value
Originally Posted by schoemr
...
This never occurred to me:
Code:
lastrow += 1
checkedRow.Cells(2).Value = lastrow
...
I was kind of mystified by that yesterday.
jmc noted it in his post.
Originally Posted by jmcilhinney
... Each time you find a checked row, you need to put the desired value, i.e. lastRow, into that row and then you need to increment that value, i.e. lastRow.
...
And you even quoted it in your response, but assumed it wouldn't work for some reason, which was the part that mystified me.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Nov 6th, 2019, 10:10 AM
#8
Addicted Member
Re: [RESOLVED] Increment value by 1 from specified value
I think every programmer has a blind spot now and then.... can't see the solution even if it bit ya in the ass
Utterly useless, but always willing to help
As a finishing touch god created the dutch
-
Nov 7th, 2019, 01:20 AM
#9
Thread Starter
Frenzied Member
Re: Increment value by 1 from specified value
Originally Posted by passel
I was kind of mystified by that yesterday.
jmc noted it in his post.
And you even quoted it in your response, but assumed it wouldn't work for some reason, which was the part that mystified me.
Hi Passel,
This is what I understood at that point in time.
Each time you find a checked row, you need to put the desired value, i.e. lastRow, into that row
Code:
checkedRow.Cells(2).Value = lastrow
then you need to increment that value
Code:
checkedRow.Cells(2).Value = lastrow + 1
That is why I said every row will have the same number then.
A simple "increment means +=" did not occur to me at that time (on the 5th November) but by the next day on the 6th November (my #6) I said that I got to that part (the +=) I just then needed the correct way of implementing it.
But Passel thank you for your contribution.
-
Nov 7th, 2019, 01:23 AM
#10
Thread Starter
Frenzied Member
Re: [RESOLVED] Increment value by 1 from specified value
Originally Posted by .paul.
It was probably closer than you think...
Code:
checkedRow.Cells(2).Value = lastRow += 1
Code:
checkedRow.Cells(2).Value = lastRow + 1
+= is an assignment and doesn't return a value. You could write...
Code:
Dim value as integer = 9
value += 1
Which is equivalent to...
Code:
Dim value as integer = 9
value = value + 1
Hi Paul, thank you very much for your time and effort to explain it to me. I much appreciate it
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
|