Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add row data manually by datagridview

Shulou Source: shulou.com Published: 2022-05-31 21:06:00 10月02日 Update

Most people do not understand the knowledge points of this article "datagridview how to add row data manually", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "datagridview how to add row data manually" article.

Datagridview manually add row data

I am doing the software model interface, through the function button to trigger the display of datagridview, for convenience, need some data, just write dead data on it, therefore, do not need to connect the data table, just add rows on it.

The code is as follows:

Int index = this.dataGridView1.Rows.Add (); this.dataGridView1.Rows [index] .cells [0] .value = "1"; this.dataGridView1.Rows [index] .cells [1] .value = "11"; this.dataGridView1.Rows.cells [2] .value = "1111"; this.dataGridView1.Rows[ index] .cells [3] .value = "11111" This.dataGridView1.Rows [index] .cells [4] .value = "111111"; this.dataGridView1.Rows[ index] .cells [5] .value = "1111111"; this.dataGridView1.Rows [index] .cells [6] .value = "*-*"; several ways for datagridview to add rows

1. Data binding

DataGridView1.AutoGenerateColumns = true;dataGridView1.DataSource = customersDataSet

This automatically generates row data for the corresponding data. If the column is not automatically generated, add the column manually and set the data source property name (DataPropertyName) of the column to the property name of the corresponding data class.

2. Add manually

SongsDataGridView.ColumnCount = 5;. SongsDataGridView.Columns [0] .Name = "Release Date";.... string [] row0 = {"11 White Album 22 1968", "29", "Revolution 9", "Beatles", "The Beatles [White Album]"}; songsDataGridView.Rows.Add (row0)

In addition, you can access row cells in this way

This.dataGridView1.Rows [1] .cells [0] .value = "new value"; / / or the equivalent this.dataGridView1 [0,1] .value = "new value". The above is about "how to manually add row data in datagridview". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Data manual content properties articles methods knowledge articles code values functions units most that is buttons data sources datasheets more models steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Xiaomi MariaDB OPPO Reno