避免将重复的条目插入到datagridview [英] Avoid inserting duplicate entries to datagridview

查看:71
本文介绍了避免将重复的条目插入到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将此代码放在插入按钮下,该按钮将值从文本框传输到datagridview.

I have placed this code under the insert button that transfers the values from the textboxes to the datagridview.

for (int nCounter = 0; nCounter <= dataGridView1.RowCount - 1; nCounter++)
            {
                if (txtrawmatno.Text == dataGridView1[2, nCounter].Value.ToString())
               {
                    MessageBox.Show("That product has been selected already.", "Repeat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

            }



我收到一条错误消息:对象引用未设置为对象的实例.
请帮忙!我想验证文本框值以避免输入重复的文本.



I''m getting an error that says: Object reference not set to an instance of an object.
please help! I want to validate the text box value to avoid entering a duplicate.

推荐答案

对象引用未设置为对象的实例

当您尝试使用属性或调用对象的方法为null时,会发生此错误.更多详细信息:此处 [
Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.


这篇关于避免将重复的条目插入到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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