Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, guys. Sorry to bother you, but I need a little help.
I have a very simple dataGridView control (4 columns, 3 of them read-only).
I need:
1) to keep users from entering characters other than 0 and natural numbers (1 to 20) on column 3. Currently, it's formatted as numeric, zero decimals, but accepts anything, including spaces.
2) to have row 0, column 3 as the selected cell when the DGV first opens, so the user can start entering information right away. So far,
SQL
this->dataGridView1->ClearSelection();
         this->dataGridView1->Rows[0]->Cells[3]->Selected = true;

are not working.
I'd appreciate your help. Thank you very much!
Posted
Updated 10-Sep-12 5:43am
v3
Comments
Sergey Alexandrovich Kryukov 10-Sep-12 15:49pm    
System.Windows.Forms? Something else? Tag it.
--SA
Mateo Hernández 11-Sep-12 2:56am    
PROBLEM SOLVED. Thanks for your reply.
It was a lot easier than I thought, and I learned a few things along the way.

1 solution

Since only a few keystrokes were harmful to the cell value, I added a
C++
CellValueChanged
event. Then filtered out the read-only columns and made a string-to-integer conversion. After that, I included a try/catch block to take care of the
C++
FormatException^
and filtered out both the numbers outside the desired range (0 to 20) and the values that included the plus sign. Not rocket science, but it got the job done!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900