Your problem to set the selection is probably related to the fact that, in order to allow a user to edit cell content, the cell does not just need to be selected, it needs to be the current cell. There can be more than one selected cell at a time but at most one current cell. This is how I did that successfully, perhaps you try that:
Validation of the numeric data input apparently does not occur before the user submits the edit (e.g. by hitting Enter) or even the DGV submits the data to the underlying database it seems to have. Yet the cell still seems to be a DataGridViewTextBoxCell, accepting any user input an ordinary textbox would. To constrain the keys accepted from the user, this procedure might help:
Attach a CellBeginEdit event handler to the data grid view. (At this point you probably don't need to check whether the cell that's about to be edited actually is one that needs to be constrained to numeric input, since it seems to me that the other cells aren't editable anyway.) Now, from inside the begin edit handler, attach a KeyPress event handler to the DGV's EditingControl which simply sets the e->Handled it got passed to true whenever it sees a character you don't want to allow the user to enter.
Somewhat complicated, but I'm afraid that's as easy as it gets. There certainly are other ways to do this, mostly involving deriving your own cell class from DataGridWiewTextBoxCell or even DataGridViewCell, which give you more control about what's actually going on, but they're also likely to be much more complicated.
Furthermore, whether the input filtering method I outlined above can work at all, depends on whether the DGV already has created its editing control when the CellBeginEdit event gets fired, which I didn't get clearly from the MSDN docs and didn't check myself.
You have seen that the data grid view is extremely powerful, but unfortunately this comes at the price that this single control is considerably more complex than some entire simpler programming languages...
Last edited by Eri523; September 10th, 2012 at 11:36 AM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Thanks so much for your reply. Before posting my question, I browsed through some of the events and CellBeginEdit caught my eye. Problem is, there are so many properties, methods and events that I get confused, and msdn doesn't always have code examples for C++ (mostly VB &C#). Let me read your post several more times and try all your suggestions. More complicated problems have been solved before. THANKS A LOT, AGAIN!
PROBLEM SOLVED!!! Thanks a lot, guys!. It turned out to be much easier than I thought, and I learned a few things along the way.
I was looking for an icon, a button, a box or something to mark this question as solved, but I donīt see anything of the kind. Thanks again!