Skada's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
8 (0.01 per day)
Joined:
07-August 11
Profile Views:
177
Last Active:
User is offline Sep 02 2011 01:20 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Skada has not set their status

Posts I've Made

  1. In Topic: Disbling a button until both column datagridview checkbox is checked.

    Posted 24 Aug 2011

    View Postsmohd, on 24 August 2011 - 12:33 AM, said:

    You may keep it in CellStateChanged,CellMouseClick or others but there is delay in it. I dont see exactly where to put this check for the case, may be on MouseMove !



    Still the same T_T Anyway. Thanks for helping me.
  2. In Topic: Disbling a button until both column datagridview checkbox is checked.

    Posted 24 Aug 2011

    View Postsmohd, on 23 August 2011 - 11:11 PM, said:

    Oh, now you need to have at least one check in every column?
    Private Function HasParentAndChild() As Boolean
            Dim hasParentCode As Boolean = False
            Dim hasChildCode As Boolean = False
            For i As Integer = 0 To DataGridView1.Rows.Count - 1
                If CBool(Me.DataGridView1.Rows(i).Cells(0).Value) = True Then
                    hasParentCode = True
                End If
    
                If CBool(Me.DataGridView1.Rows(i).Cells(1).Value) = True Then
                    hasChildCode = True
                End If
                If hasParentCode AndAlso hasChildCode Then
                    Return true
                End If
            Next
    Return false
    End Function
    


    Expecting this will do the work


    It's working..but still not what we want to happen.. I dont know how to explain that's why I attached pictures.
  3. In Topic: Disbling a button until both column datagridview checkbox is checked.

    Posted 23 Aug 2011

    View Postsmohd, on 23 August 2011 - 11:11 PM, said:

    Oh, now you need to have at least one check in every column?
    Private Function HasParentAndChild() As Boolean
            Dim hasParentCode As Boolean = False
            Dim hasChildCode As Boolean = False
            For i As Integer = 0 To DataGridView1.Rows.Count - 1
                If CBool(Me.DataGridView1.Rows(i).Cells(0).Value) = True Then
                    hasParentCode = True
                End If
    
                If CBool(Me.DataGridView1.Rows(i).Cells(1).Value) = True Then
                    hasChildCode = True
                End If
                If hasParentCode AndAlso hasChildCode Then
                    Return true
                End If
            Next
    Return false
    End Function
    


    Expecting this will do the work



    If HasParentAndChild() Then
                btnConso.Enabled = True
            Else
                btnConso.Enabled = False
            End If
    



    How about this? Where will I put this? What event? Is this right? Do I need to do something else? :)
  4. In Topic: Disbling a button until both column datagridview checkbox is checked.

    Posted 23 Aug 2011

    View Postsmohd, on 23 August 2011 - 09:29 PM, said:

    I think you want to check if all DataGridViewCheckBoxCell are checked?
    First try to go to count -2, then look at your method, you since you need all check boxes to be checked, you can simply have
     For i As Integer = 0 To DataGridView1.Rows.Count - 2
     If CBool(Me.DataGridView1.Rows(i).Cells(0).Value) = True andAlso CBool(Me.DataGridView1.Rows(i).Cells(1).Value) = True Then
      'just ignore
     Else
      return false
     End If
    Next
    asParentAndChild = true 
    


    If this doest work please tell us more if all check boxes or not and you can give a screenshoot of your datagrid view..


    No, Sir. What I want is that simply check if both datagridviewcheckboxes colums (PARENT AND CHILD) has checks in them,no matter how many checks. the button will be enabled once the two checkbox columns has checks, if one only or none it must remain disabled.
  5. In Topic: Disbling a button until both column datagridview checkbox is checked.

    Posted 23 Aug 2011

    View PostPsyguy, on 22 August 2011 - 11:56 AM, said:

    I am going to go ahead and assume you are checking to see if a certain row has both a parent and a child before returning true.

    IF that is the case, then I see one problem (maybe not the one you were looking for) and that is that you are not resetting the hasParentCode/hasChildCode boolean values to false after or before each loop iteration. The problem that will cause is that you may get a hasParentCode in one row and a hasChildCode in a different row which would return true. I'll take a crack at the code for what I mean:

    Private Function HasParentAndChild() As Boolean
    
            Dim result as Boolean = False
            For i As Integer = 0 To DataGridView1.Rows.Count - 1            
                If CBool(Me.DataGridView1.Rows(i).Cells(0).Value) = True andalso
                         CBool(Me.DataGridView1.Rows(i).Cells(1).Value) = True Then
                    result = True
                    Exit For
                End If
            Next
            hasParentAndChild = result
    End Function
    
    


    I combined your two IF statements into a single IF that checks for both to be true. I also got rid of the two return calls and opted for one (my college professor marked me off points on a test once and said you should never have more than one return statement :)) If I understand what you are going for here, this should be a little closer to what you need.

    EDIT:
    If you don't care where the true values show up, then your original if/elseif statement should work fine.



    The button remains false.

    I tried this, but still the remains false. (Disabled)

    Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
            If HasParentAndChild() Then
                btnConso.Enabled = True
            Else
                btnConso.Enabled = False
            End If
        End Sub
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Skada hasn't added any friends yet.

Comments

Skada has no profile comments yet. Why not say hello?