c ++/cli dataGridView单元格 [英] c++/cli dataGridView cells
问题描述
伙计们.抱歉打扰您,但我需要一点帮助.
我有一个非常简单的dataGridView控件(4列,其中3列为只读).
我需要:
1)防止用户在第3列上输入0和自然数(1到20)以外的字符.当前,其格式设置为数字,十进制零,但可以接受任何内容,包括空格.
2)在DGV首次打开时,将第0行,第3列作为选定的单元格,因此用户可以立即开始输入信息.到目前为止,
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,
this->dataGridView1->ClearSelection();
this->dataGridView1->Rows[0]->Cells[3]->Selected = true;
不起作用.
非常感谢您的帮助.非常感谢您!
are not working.
I''d appreciate your help. Thank you very much!
推荐答案
由于只有几次按键操作对单元格值有害,因此我添加了
Since only a few keystrokes were harmful to the cell value, I added a
CellValueChanged
事件.然后过滤掉只读列并进行字符串到整数的转换.之后,我加入了一个try/catch块来处理
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
FormatException^
,并过滤掉超出所需范围(0到20)的数字以及包括加号.不是火箭科学,但工作就完成了!
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!
这篇关于c ++/cli dataGridView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!