Datagrid视图问题 [英] Datagrid view Issues

查看:70
本文介绍了Datagrid视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同性恋,



我在这个应用程序中创建Windows应用程序。我创建了1个表单,在这个表单中我使用数据网格视图。





在网格中我检查一些验证,如值必须是整数当验证单元格....如果值不是整数然后我想执行e.cancel

但在单元格验证事件e.cancel不工作....任何替代解决方案???





thx in adv。

hi gays,

i create windows application and in this app. i create 1 form, in this form i use data-grid view.


in grid i check some validation like value must be integer when validate cell....if value is not integer then i want to perform "e.cancel"
but in cell validated event e.cancel not work....any alternate solution???


thx in adv.

推荐答案

现在我们刚刚关于足够的信息以了解问题是什么...

您已将此代码放在CellValidated事件中
Now that we have just about enough information to get an idea of what the problem is ...
You have put this code in the CellValidated event which
引用:

在单元格完成验证后发生。

"Occurs after the cell has finished validating."

引用突出显示该事件时出现在属性窗口中的文本。

尝试将验证放入CellValidating将为您提供e.Cancel 的活动



试图让它更清晰...

to quote the text that appears in the properties window when you highlight that event.
Try putting the validation in the CellValidating event where e.Cancel will be available to you

Attempting to make it clearer ...

private void dgvItemDetails_CellValidated(object sender, DataGridViewCellEventArgs e)
 {
     // It is pointless to try to "validate" after the cell has validated
     //if (Convert.ToString(dgvItemDetails["QTY", e.RowIndex].Value).Contains("-."))
     //{
     //    MessageBox.Show(this, "Please enter proper numeric value.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     //    //e.Cancel = true;
     //    return;
     //}
 }

 private void dgvItemDetails_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     // This is the event to use to validate
     if (Convert.ToString(dgvItemDetails["QTY", e.RowIndex].Value).Contains("-."))
     {
         //This line does not compile in VS2010 MessageBox.Show(this, "Please enter proper numeric value.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         MessageBox.Show(this, "Please enter proper numeric value.", "Error Caption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         e.Cancel = true;   // This is now available to you
         return;
     }
 }


这篇关于Datagrid视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆