Simon Harriyott

Developer Xpress XtraGrid: adding a row in a hidden grid

Just had one of those mammoth "two of us trying to debug something weird for ages" sessions, which was ultimately successful, and hence rather satisfying.

The problem was in a DevX XtraGrid which was on the third tab of a tabbed form. Calling AddNewRow(), setting the data and then UpdateCurrentRow() on the grid only worked if the third tab had been clicked on. If the grid hadn't been made visible, then the row wasn't added.

Having tried a few things, I came across this
seemingly unrelated forum entry, and a hunch prompted me to download the example file. After chatting to the hunch for a bit, he went away, and I looked at the source in the example. Right in the middle of the example was a call to ForceInitialize(). I had no (okay, some) idea what it was, but I had an inkling that it might be worth trying.

Once I'd finished the inkling (which was delicious), I ran through the debugger again, and it worked. It seems that ForceInitialize() forces an initialise that would normally be forced when actually viewing the control for the first time.

[Tags: ]
30 August 2006