S
S
shutov_952019-07-03 18:45:03
OOP
shutov_95, 2019-07-03 18:45:03

Still "Index out of range"?

It throws an error that is not yet clear with what it is connected with.
The data in the dgv is placed from the access database. At first I thought that this could be due to the fact that the 5th column of dgv at the time of the attempt to enter data into it is simply not defined (whether xs is determined automatically).
As a result, due to the difficulties of transferring the database from access, instead of determining the number of columns, I decided to add them to the database file.
Still didn't help.
What could be the problem?

for (int x = 0; x < 36; x++)
            {
                switch (x / 3)
                {
                    case 0:
                        {
                            mas[x, 0] = mas[x, 0] * k1 * k11;
                            mas[x, 1] = mas[x, 1] * k1 * k11;
                            mas[x, 2] = mas[x, 2] * k1 * k11;
                            mas[x, 3] = mas[x, 3] * k1 * k11;
                            dataGridView1[5, x].Value = mas[x, 0];  //на этой строчке выдаёт ошибку
                            dataGridView1[6, x].Value = mas[x, 1];
                            dataGridView1[7, x].Value = mas[x, 2];
                            dataGridView1[8, x].Value = mas[x, 3];
                            break;
                        }

Details

System.ArgumentOutOfRangeException
HResult=0x80131502
Сообщение = Индекс за пределами диапазона. Индекс должен быть положительным числом, а его размер не должен превышать размер коллекции.
Имя параметра: index
Источник = mscorlib
Трассировка стека:
в System.Collections.ArrayList.get_Item(Int32 index)
в System.Windows.Forms.DataGridViewCellCollection.get_Item(Int32 index)
в System.Windows.Forms.DataGridView.get_Item(Int32 columnIndex, Int32 rowIndex)
в Diplom.Form1.Button1_Click(Object sender, EventArgs e) в C:\Users\Vladimir\source\repos\Diplom1\Diplom\Form1.cs:строка 295
в System.Windows.Forms.Control.OnClick(EventArgs e)
в System.Windows.Forms.Button.OnClick(EventArgs e)
в System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
в System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
в System.Windows.Forms.Control.WndProc(Message& m)
в System.Windows.Forms.ButtonBase.WndProc(Message& m)
в System.Windows.Forms.Button.WndProc(Message& m)
в System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
в System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
в System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
в System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
в System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
в System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
в System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
в System.Windows.Forms.Application.Run(Form mainForm)
в Diplom.Program.Main() в C:\Users\Vladimir\source\repos\Diplom1\Diplom\Program.cs:строка 19

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2019-07-03
@Griboks

OMG, maybe you still need to write a program for you? What is your problem?
1. Get an exception
2. See the index
3. See the range
4. Find the bug
First read the introduction to C# and Visual Studio, then google, then the toaster, then ask a question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question