错误:索引超出范围.必须为非负数且小于集合的大小.参数名称:索引 [英] Error:Index out of range.must be non negitive and less than the size of the collection.parameter name:index

查看:274
本文介绍了错误:索引超出范围.必须为非负数且小于集合的大小.参数名称:索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过添加以下行来更改datagridview中列的宽度

I am trying to change width of column in datagridview by adding these lines

Dim column As DataGridViewColumn = DataGridView1.Columns(0)

           column.Width = 50


但是我收到错误:索引超出范围.必须是非负数并且小于collection.size的参数名称:index

谁能帮助我..


But i am getting ERROR:Index out of range.must be non negitive and less than the size of the collection.parameter name:index

can anyone help me plz..

推荐答案

设置DataGridView Coulumn的宽度
您首先需要用必填数据填充它.如果它没有任何数据,则肯定会引发此异常.首先设置DataGridView的数据源,然后添加代码以设置宽度.此外,如果您的数据库表中没有数据,那么也会发生此问题.
使用尝试捕获异常"处理可删除此异常.
另外,也可以用两行代码代替编写此代码,
DataGridView1.Columns(0).width = 50
试试这个
To set the Width of your DataGridView Coulumn
you First need to fill it with the Required Data.If it will not have any data it will surely throw this exception.Set the Datasource of DataGridView First, then add the code to set the width.Also if in your Database table there is no data then also this problem will happen.
Use Try Catch Exception handling to remove this exception.
Also in place of writing the this code in two line you can reduce it to
DataGridView1.Columns(0).width =50
Try this


这篇关于错误:索引超出范围.必须为非负数且小于集合的大小.参数名称:索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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