Windows Develop Bookmark and Share   
 index > Windows Forms General > How can i insret row at the end of datagridview using vb.net
 

How can i insret row at the end of datagridview using vb.net

How can i insret empty row at the end of datagridview using vb.net. when i use

Me

.DGVmWatchTemplate.Rows.Insert( Me.DGVTemplate.Rows.Count, 1)

the following exception occurs

No row can be inserted after the uncommitted new row.

BUT when i use the following code the row added successfully but at the middle not inserted at the end of the grid....

Me

.DGVmWatchTemplate.Rows.Add()




Ather...
Ather.Abbas  Monday, October 05, 2009 10:24 AM
Hi,

I can use the following code to handle the above scenario , i think may it help for you.

Dim dr As DataRow = CType(DGVTemplate.DataSource, DataTable).NewRow
        CType(DGVTemplate.DataSource, DataTable).Rows.Add(dr)

Good luck
Malik M.Shahid  Monday, October 05, 2009 1:15 PM

Hi,

 

As the error message said, No row can be inserted after the uncommitted new row.

 

If DataGridView.AllowUserToAddRows property is set to true (default setting), a special row for adding new rows appears as the last row. It is marked with an asterisk (*) symbol in its row header. This row is part of the Rows collection, but it has special functionality that may require your attention. Please see

Using the Row for New Records in the Windows Forms DataGridView Control

http://msdn.microsoft.com/en-us/library/ka3w9f4d.aspx

 

If you want insert row at the end of datagridview, you can set datagridview.AllowUserToAddRows to false, or insert at Me.DGVTemplate.Rows.Count -1 .

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  1 hour 0 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Button question
• Help with migration from VB to C# (re: form controls)
• Disappearing controls
• Clickable ErrorProvider
• Windows Forms Multi-Threading
• listview scrollbar disappears with vista (c# code) but not with xp
• how to add n number of controls at runtime?
• Webbrowser control on XP SP2 with IE7
• Open HTML documents in Microsoft Word
• Moving thruogh forms