指数超出范围。在以win形式读取datagrid视图时,必须是非负数且小于collection.issue的大小 [英] Index was out of range. Must be non-negative and less than the size of the collection.issue while reading datagrid view in win form

查看:61
本文介绍了指数超出范围。在以win形式读取datagrid视图时,必须是非负数且小于collection.issue的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i ma试图从其他类中读取其他类中的datagridview。

但是获得此激活



hi

i ma trying to read the datagridview which is in other class from onther class.
but getting this excpetion

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

推荐答案

我们不能在没有看到导致错误的代码的情况下确切地说出问题是什么,但首先要做的就是停止访问其他类的控件。



这是针对OOP的原则,它将两个类联系在一起,这意味着你不能在不考虑对另一个的影响的情况下改变其中一个。无论如何,在类之间传递信息,但是使用属性和敏感数据结构,例如List,IEnumerable或DataTable / DataSet。传递控件是一个非常糟糕的主意...



这里有一些关于如何正确操作的信息:

在两种表格之间转移信息,第1部分:父母对孩子 [ ^ ] br />
在两种表格之间传递信息,第2部分:儿童到家长 [ ^ ]

在两种表格之间传递信息,第3部分:儿童与儿童 [ ^ ]
We can't tell exactly what the problem is without seeing the code that causes the error, but the first thing to do is stop accessing controls on other classes at all.

It's against the principles of OOP, it ties the two classes together and it means you can't change one of them without considering the effects on the other. By all means, pass information between the classes, but use Properties and sensible data structures such as List, IEnumerable or DataTable/DataSet instead. Passing controls is a very poor idea...

There is some info on how to do it properly here:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]


这篇关于指数超出范围。在以win形式读取datagrid视图时,必须是非负数且小于collection.issue的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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