Как вывести массив в datagridview c
Перейти к содержимому

Как вывести массив в datagridview c

Как вывести массив в datagridview c

Вызываем функцию передавая в нее текстовый массив и ссылку на DataGridView

addGridParam

‘функция заполнения таблицы

‘N — массив который мы хотим отобразить

‘Grid — ссылка на визуальный компонент DataGridView для отобажения в ней информации

Public Sub addGridParam(N As String (), Grid As DataGridView )

‘если длинна массива больше чем количество элементов массива то добавляем столбцы

donitox / dataGridView.cs

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

dataGridView1 . RowCount = N ;
dataGridView1 . ColumnCount = M ;
int i , j ;
for ( i = 0 ; i < N ; ++ i )
for ( j = 0 ; j < M ; ++ j )
dataGridView1 . Rows [ i ]. Cells [ j ]. Value = mas [ i , j ];

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Show 2d-array in DataGridView

I have a 2D array. I want to print the array in my DataGridView but it throws an error:

[Argument OutOfRangeException was unhandled ]

This is my code

user avatar

3 Answers 3

As comments have pointed out, you should focus on rows and cells. You need to build your DataGridView columns and then populate each row cell by cell.

The width of your array should correspond to your dgv columns and the height to the dgv rows. Take the following as a simple example:

user avatar

for exemple for 2 elements

user avatar

The first potential problem is with how you are accessing your array indexes. Which can be handled this way.

Just check your array dimension length first. Clearly one of your variables height or width is incorrect.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *