Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. DataGridView checkbox column problem

DataGridView checkbox column problem

Scheduled Pinned Locked Moved Visual Basic
csshelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paukiPkk
    wrote on last edited by
    #1

    I want to display some invoice details in a datagridview (dgv). I want the user to be able to click a check box, which I've added to the dgv, so that they can indicate whether they want the invoice amount or invoice total to be used in calculations on that invoice. There are boolean properties called UseInvAmount and UseInvTotal in the invoice object. I can get the check box to appear in the grid okay, but clicking on it does not make a check appear, even though the cellContentClick sub fires when the checkBox cell is clicked. I've got code that handles the 2 events: cellValueNeeded & cellValuePushed, and I've also added 2 event handlers to the dgv (DataGridViewCellEventHandler & DataGridViewRowsAddedEventHandler) and registered the dgv's "with events", but the cellValueNeeded and cellValuePushed code are not triggered by clicking on the checkboxes. Can anyone tell me what I've left out or how to make a checkbox click on & off, and work independently of another one? Pauki

    S 1 Reply Last reply
    0
    • P paukiPkk

      I want to display some invoice details in a datagridview (dgv). I want the user to be able to click a check box, which I've added to the dgv, so that they can indicate whether they want the invoice amount or invoice total to be used in calculations on that invoice. There are boolean properties called UseInvAmount and UseInvTotal in the invoice object. I can get the check box to appear in the grid okay, but clicking on it does not make a check appear, even though the cellContentClick sub fires when the checkBox cell is clicked. I've got code that handles the 2 events: cellValueNeeded & cellValuePushed, and I've also added 2 event handlers to the dgv (DataGridViewCellEventHandler & DataGridViewRowsAddedEventHandler) and registered the dgv's "with events", but the cellValueNeeded and cellValuePushed code are not triggered by clicking on the checkboxes. Can anyone tell me what I've left out or how to make a checkbox click on & off, and work independently of another one? Pauki

      S Offline
      S Offline
      shally_79
      wrote on last edited by
      #2

      i cannot understand your requirement fully pauki.the event CellValueChanged is fired after a checkbox is checked.but before handling that event u have to handle one more even ie CurrentCellDirtyStateChanged.i have given that code below Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged Try If DataGridView1.IsCurrentCellDirty Then DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) End If Catch ex As Exception End Try End Sub after that handle the event CellValueChanged like this If e.RowIndex > 0 Then If DataGridView1.Item(0, e.RowIndex).Value Then MsgBox("hello") End If End If if u need more explantion reply:rose:

      shally

      P 1 Reply Last reply
      0
      • S shally_79

        i cannot understand your requirement fully pauki.the event CellValueChanged is fired after a checkbox is checked.but before handling that event u have to handle one more even ie CurrentCellDirtyStateChanged.i have given that code below Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged Try If DataGridView1.IsCurrentCellDirty Then DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit) End If Catch ex As Exception End Try End Sub after that handle the event CellValueChanged like this If e.RowIndex > 0 Then If DataGridView1.Item(0, e.RowIndex).Value Then MsgBox("hello") End If End If if u need more explantion reply:rose:

        shally

        P Offline
        P Offline
        paukiPkk
        wrote on last edited by
        #3

        thanx Shally, I did actually try this code too, and altho it fired, I was still bothered by the fact that it didn't automatically set the check in the box (I guess I could try to set the value in the checkbox, but instead I tried using 1 unbound checkbox, useInvTotal, rather than the 2 bound boolean properties, and that seemed to work). I can't believe that it's so complicated just to get a checkbox to write back to the db - (i.e. cellContentClick is also fired on clicking a cell, and all this need for cellValueNeeded, cellValuePushed etc. to set the initial values...) I'll see if I can get your suggestion to work anyway. thanks again, PK

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups