Results 1 to 4 of 4

Thread: [RESOLVED] Datagridview checkbox problem

  1. #1

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Resolved [RESOLVED] Datagridview checkbox problem

    Hello. Please bear with me I'm new to vb.net.
    I have this datagridview problem.

    Scenario:

    My Database columns.
    Code:
    -isCleared (boolean)
    -DateCleared (DateTime)
    My DGV Columns:
    Code:
    -isCleared Column (CheckBox)
    -DateCleared Column (Readonly Textbox)
    My DGV will only accept edits.

    What I want to accomplish in a row level (logic). I can't find the right DGV event to execute this logic.
    Code:
    if dgv.CurrentRow.Cells("IsCleared").Value = True then
       dgv.CurrentRow.Cells("DateCleared").Value = Date.Today
    else
        dgv.CurrentRow.Cells("DateCleared").Value = nothing or dbnull?
    end if

    I tried experimenting with the DGV events I can't seem to make it work. All I get is a delayed effect.
    Last edited by coolwater; Nov 22nd, 2013 at 08:05 AM.

  2. #2

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Datagridview checkbox problem

    I got it. I read a solution from this link http://geekswithblogs.net/FrostRed/a...07/125001.aspx

  3. #3
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: [RESOLVED] Datagridview checkbox problem

    Hi,

    Good to see that you have solved this for yourself but here is another option for you using the CellContentClick Event of the DataGridView:-

    vb.net Code:
    1. Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    2.   If e.ColumnIndex = 0 Then
    3.     If CBool(DataGridView1.CurrentCell.EditedFormattedValue) Then
    4.       DataGridView1.CurrentRow.Cells("DateCleared").Value = Today
    5.     Else
    6.       DataGridView1.CurrentRow.Cells("DateCleared").Value = DBNull.Value
    7.     End If
    8.   End If
    9. End Sub

    Cheers,

    Ian

  4. #4

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Resolved Re: [RESOLVED] Datagridview checkbox problem

    Quote Originally Posted by IanRyder View Post
    Hi,

    Good to see that you have solved this for yourself but here is another option for you using the CellContentClick Event of the DataGridView:-

    vb.net Code:
    1. Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    2.   If e.ColumnIndex = 0 Then
    3.     If CBool(DataGridView1.CurrentCell.EditedFormattedValue) Then
    4.       DataGridView1.CurrentRow.Cells("DateCleared").Value = Today
    5.     Else
    6.       DataGridView1.CurrentRow.Cells("DateCleared").Value = DBNull.Value
    7.     End If
    8.   End If
    9. End Sub

    Cheers,

    Ian

    Thanks IanRyder. I like your solution. It's better.
    Last edited by coolwater; Nov 23rd, 2013 at 02:26 AM.

Tags for this Thread

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