Results 1 to 2 of 2

Thread: disable click on cell

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    9

    disable click on cell

    Hi guys!

    I have a problem with my datagridview.

    here goes:

    1. I have a datagridview that displays borrower's information.

    2. upon click on the leftside button of the row (fullrowselect) the controls are auto populated with data. (userid, library card no. etc..)

    3.here is my datagridview cell click event code:

    Code:
    Private Sub grdBorrowers_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdBorrowers.CellClick
            
            With borrowers
    
                Try
                    If borrowers.selectborrower(grdBorrowers.CurrentCell.Value) = True Then
                        load_data()
                    End If
                    Exit Sub
    
                Catch Err As DataException
                    MsgBox(MSG_ERR)
                End Try
    
            End With
        End Sub
    4. here is my select statement to populate the controls:

    Code:
     Public Function selectborrower(ByVal mvuserid As Integer) As Boolean
                Try
                    SqlExec = ""
                    SqlExec = SqlExec & "select" & vbCr
                    SqlExec = SqlExec & "userid," & vbCr
                    SqlExec = SqlExec & "libcardno," & vbCr
                    SqlExec = SqlExec & "borrowertype," & vbCr
    
                    SqlExec = SqlExec & "empstudno," & vbCr
    
                    SqlExec = SqlExec & "fname," & vbCr
                    SqlExec = SqlExec & "mname," & vbCr
                    SqlExec = SqlExec & "lname," & vbCr
    
                    SqlExec = SqlExec & "address," & vbCr
                    SqlExec = SqlExec & "birthdate," & vbCr
                    SqlExec = SqlExec & "gender," & vbCr
                    SqlExec = SqlExec & "contactno," & vbCr
    
                    SqlExec = SqlExec & "picpath," & vbCr
                    'SqlExec = SqlExec & "referflag," & vbCr
                    SqlExec = SqlExec & "remarks," & vbCr
                    SqlExec = SqlExec & "regdate," & vbCr
                    SqlExec = SqlExec & "endregdate," & vbCr
                    SqlExec = SqlExec & "deleteflag" & vbCr
    
                    SqlExec = SqlExec & "FROM borrowers" & vbCr
                    SqlExec = SqlExec & "where userid =" & mvuserid & " " & vbCr
                    SqlExec = SqlExec & "and DeleteFlag = 0" & " " & vbCr
    
    
                    SqlCon.Open()
                    SqlCmd = New SqlCommand(SqlExec, SqlCon)
                    SqlDR = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
    
                    Do While SqlDR.Read
    
                        userid = (SqlDR("userid"))
                        libcardno = (SqlDR("libcardno"))
                        borrowertype = (SqlDR("borrowertype"))
                        empstudno = (SqlDR("empstudno"))
                        fname = (SqlDR("fname"))
                        mname = (SqlDR("mname"))
                        lname = (SqlDR("lname"))
                        address = (SqlDR("address"))
                        birthdate = (SqlDR("birthdate"))
                        gender = (SqlDR("gender"))
                        contactno = (SqlDR("contactno"))
                        picpath = (SqlDR("picpath"))
                        'referflag = (SqlDR("referflag"))
                        remarks = (SqlDR("remarks"))
                        regdate = (SqlDR("regdate"))
                        endregdate = (SqlDR("endregdate"))
                        deleteflag = (SqlDR("deleteflag"))
    
                    Loop
                    SqlDR.Close()
                    SqlCon.Close()
    
                    selectborrower = True
                    Exit Function
    
                    selectborrower = False
                    SqlCon.Close()
                Catch err As SqlException
                    MsgBox(err.Message)
                End Try
            End Function
    4. the problem is when i click on a cell that is not an integer it creates an error.

    5. my idea is to disable the cells inside the grid. only userid or the leftside button should be enabled. how can i do that? is that possible?

    thanks in advance for the help! I really appreciate it! more power to the group!
    Last edited by gep13; Oct 6th, 2011 at 01:42 AM. Reason: Added Code Tags

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: disable click on cell

    Hello jnavarro.ph,

    When you are posting code into the forum, can you please remember to surround it in [code][/code] or [HIGHLIGHT=vb][/highlight] tags? It makes it a lot easier to read. I have done this for you in your above post.

    Thanks

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width