Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi this is the first time I am working with datagridview. I want to add rows to datagridview on button click, the rows should be blank. When I select a row and clikc edit button that row should be editable. Is it possible can anyone help with code snippet for proceeding

Thanks in advance
Posted

Hello,

First you must add columns to your datagridview like this:
C#
datagridview1.columns.add("Column1");
datagridview1.columns.add("Column2");
datagridview1.columns.add("Column3");


Now you can add rows like this:
C#
datagridview1.rows.add("", "", "");

3 Parameters because your datagridview has 3 columns.

If the datagridview isn't in "readonly-mode" you can edit the data.
 
Share this answer
 
v2
Go through some tutorials[^].
 
Share this answer
 
Comments
Member 10508337 17-Jan-22 1:16am    
Private Sub SurroundingSub()
Dim rowId As Integer = dataGridView1.Rows.Add()
Dim row As DataGridViewRow = dataGridView1.Rows(rowId)
row.Cells("Column1").Value = "Value1"
row.Cells("Column2").Value = "Value2"
End Sub
The above code does not help me add a row to the Grid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900