Home > Net >  Winform/GataGridView index scope. Must be a negative and less than the set size
Winform/GataGridView index scope. Must be a negative and less than the set size

Time:10-18

. I am using datagridview1 Columns [0]. The HeaderText modify column names, appear "index beyond range, must be a negative and less than the set size",
Check the datagridview1. Columns. The Count value is 0;

But when I was in the running program, is, indeed, there are data, paste the code below:

The DataSet data1=new DataSet ();

Data1=new ConnectionSql (.) GetItemInfo ();//ConnectionSql () custom class, ConnectionSql () GetItemInfo () returns a DataSet;

Enclosing datagridview1. The DataSource=data1. Tables [0].

This. Datagridview1. Columns [0]. The HeaderText="bar code";//here shows index beyond the scope of the
Console. WriteLine (datagridview1. Columns. The Count);//print here is 0




CodePudding user response:

Delete the error of a line, execute code do have data,



CodePudding user response:

That is also no data when you visit ah. You print is 0, that data is not loaded, change the timing to perform datagridview1. Columns [0]. The HeaderText=... this

CodePudding user response:

refer to the second floor ziqi0716 response:
that is also no data when you visit ah. You print is 0, that data is not loaded, change the timing to perform datagridview1. Columns [0]. The HeaderText=... The


That should be performed where?

Enclosing datagridview1. The DataSource=data1. Tables [0].
There should be no data?
  •  Tags:  
  • C#
  • Related