Sunday, July 20, 2008

Special kind of error

I tried to cast an internal control to TwwDBGrid as a TwwCheckBox and use it's Checked property. All I can say is WOW!

Here's the follow on error

That is a special error. As in "Special Education".

6 comments:

  1. Why would you want to case a grid to a checkbox? That's not a very usefull cast, is it?

    ReplyDelete
  2. What I was trying to do was get the boolean value from inside the checkbox, which is built into TwwDBGrid. I could grab any other value from the TwwDBGrid except that one, which for some reason would always return null. I couldn't sort it out through either google or tamarack. I saw a code example where someone got the internal checkbox from TwwDBGrid as a generic object, and then cast that internal object as a TwwCheckbox, then they were able to use the *.Checked property. I tried to follow their example, and I got the above error. I probably didn't get the proper internal object, or the version of TwwDBGrid that I have uses a different kind of widget for a checkbox.

    ReplyDelete
  3. I think the odds that a dbgrid inherits from a checkbox is close to nonexistent. You probably saw an example where one of the columns in the grid was defined as a checkbox (editor) and they tried to get a value of a field displayed in the grid via a checkbox.

    I don't know TwwDBGrid at all, but probably you would have something like:

    TwwCheckBox(myGrid.Rows[myGrid.CurrentRow].Fields[checkboxField.Index]).Checked.

    Odds are that you probably can get the value you are looking for using the dataset that's linked to the grid.

    ReplyDelete
  4. Your code snippet is exactly what I was trying to do. My guess was that TwwDBGrid instantiates other objects inside itself such as checkboxes, comboboxes, etc. So I was trying to cast an object that was inside TwwDBGrid when I got the funky error.

    Also, I tried using the dataset, same result, all nulls. I don't know if a TwwDBGrid automatically posts changes to the dataset, but the checkbox is user clickable. I don't need to incorporate the check into the dataset, as it's sole purpose was to denote additional processing to be done immediately on that record (thus, no need to store the check). So I figured since I'm not posting the check back to the dataset, there would be no check in the dataset for me to read.

    ReplyDelete
  5. Maybe you can put your exact code here as it is now a bit of guess work. Again, I'd love to help, but without the exact code, it's a bit hard to do.

    ReplyDelete
  6. Hmmm.. Try to change the focus to a near column on the wwdbgrid. I think that would make reflect the wwdbcheckbox state on the TDataset field.

    ReplyDelete