Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
What is the best event to track when a checkbox is clicked
posted

Alrighty, I am having a tough time narrowing this down. I have a simple grid...2 columns...1 with a checkbox, the other is a readonly string.

 My goal is to update the UI whenever the checkbox is checked or unchecked, but it isn't working the way I expect.

If I use the AfterCellUpdate event, then nothing gets fired till the user clicks off of the row. That is too confusing.

If I use the CellChange event, then I can't seem to reliably find out whether the user just checked or unchecked the item.

If I  use the MouseClick event then all sorts of screwy stuff starts happening.

What event is closest to the standard CheckChanged event on a normal checkbox? I wouldn't think this would be all that tricky...

 David

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

     Hi,

        The proper event to use is CellChange. You need to use the Text property of the cell to determine the current value of the checkbox. Value will not have ben updated, yet.

         At first glance, this probably does not make a lot of sense. And for a checkbox cell, it really doesn't. But to understand why this is the case, think about a DateTime cell.

        Suppose I have a grid with a DataTime cell and I want to change the date to "12/25/07". I would click on the cell and delete the contents and then type in some numbers. But it would not make sense for the grid to update the cell on every keystroke. The first key I typed would be a number "1", and this would not be a valid date. So what happens is that while the cell is in edit mode, the Value of the cell (which returns a DateTime) may not be valid if it's based on what I am typing. So the Value property of the cell does not look at what I type as I type it, it reads from the underying data source. To get what's actually typed into the cell at any given moment, I need to check the Text property. This is always okay, because anything I type can be represented as a string. It is only when the cell loses focus that the grid figures the user is done typing and tries to take the text you typed in and convert it to a valid date.

        The checkbox cell would not have this problem, of course, since the user can't type anything invalid into it, but the grid still has to work the same way. So when you click the checkbox, only the Text property is updated, and the Value does not get updated until you leave the cell.

Children