Datagridview
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Datagridview

  1. #1
    Join Date
    Feb 2009
    Posts
    189

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

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

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2009
    Posts
    189

    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

  4. #4
    Join Date
    Apr 2012
    Posts
    28

    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"

  5. #5
    Join Date
    Feb 2009
    Posts
    189

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center