-
June 28th, 2012, 11:26 AM
#1
Datagridview
Hi,
At run time, if I Click ToolBarButton1 - I can still check/uncheck the checkbox at Cell 3 even if the value is "Old" at Cell 2.
Thanks
Code:
If e.Button Is ToolBarButton1 Then
Dim irowNo As Integer
For irowNo = 0 To DgvPracExcl.Rows.Count - 1
If DgvPracExcl.Rows(irowNo).Cells(2).ToString() = "old" Then
DgvPracExcl.Rows(irowNo).Cells(3).ReadOnly = True
Else
DgvPracExcl.Rows(irowNo).Cells(3).ReadOnly = False
End If
Next irowNo
End If
-
June 28th, 2012, 11:58 AM
#2
Re: Datagridview
You'll need to skip line 0, then start comparing ircNo+1 to ircNo each time, unless it's an odd number of items. Might need another condition to handle that
Code:
If e.Button Is ToolBarButton1 Then
Dim irowNo As Integer, OldValue as String
For irowNo = 0 To DgvPracExcl.Rows.Count - 1
if rowNo = 0 Then
oldValue = "None"
else
oldValue = oldValue
End If
If DgvPracExcl.Rows(irowNo).Cells(2).ToString() = "old" Then ' or the correct string to compare?
oldValue = DgvPracExcl.Rows(irowNo).Cells(2).ToString()
End If
' Now compare
If DgvPracExcl.Rows(irowNo).Cells(2).ToString() = oldValue
DgvPracExcl.Rows(irowNo).Cells(3).ReadOnly = True
Else
DgvPracExcl.Rows(irowNo).Cells(3).ReadOnly = False
End If
Next irowNo
Free-hand...
-
June 29th, 2012, 10:23 AM
#3
Re: Datagridview
The above code did nt work - I can still chnage the Cell 2 - even if when its "Old".
ReadOnly = True doesnt take effect..
Any help
-
June 29th, 2012, 12:38 PM
#4
Re: Datagridview
Did you put a breakpoint to see if it is actually setting ReadOnly to True ? Your comparison is case-sensitive hence "Old" is not equal to "old"
-
July 3rd, 2012, 06:49 AM
#5
Re: Datagridview
Code:
Dim rowNo As Integer
Dim irowNo As Integer, OldValue As String
For irowNo = 0 To DgvPracExcl.Rows.Count - 1
If rowNo = 0 Then
OldValue = "None"
Else
OldValue = OldValue
End If
If DgvPracExcl.Rows(irowNo).Cells(2).ToString() = "old" Then ' or the correct string to compare?
OldValue = DgvPracExcl.Rows(irowNo).Cells(2).ToString()
End If
' Now compare
If DgvPracExcl.Rows(irowNo).Cells(2).ToString() = OldValue Then
DgvPracExcl.Rows(irowNo).Cells(3).ReadOnly = True
Else
DgvPracExcl.Rows(irowNo).Cells(3).ReadOnly = False
End If
Next irowNo
warning:
Variable OLDVALUE - is used before it has been assigned a value. A null reference exception could result at runtime.
Yes - it doesnt work!!
Last edited by dr223; July 3rd, 2012 at 07:09 AM.
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
|