How to remove new rows from the DataGrid

Source: Internet
Author: User
Datagrid

We often encounter this problem in programming, and we want the ReadOnly property of the DataGrid to be false and modify the data directly in the DataGrid. But do not want to let it appear new line, this problem a lot of netizens asked, in fact, to achieve a very simple, but we did not think just. The following is illustrated by a simple example

First, add a DataGrid and Button buttons to the interface, name defaults, and double-click Button1 to write the following code.

Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click

DTNEW.COLUMNS.ADD ("Time", GetType (String))
DTNEW.COLUMNS.ADD ("Cost", GetType (String))
Dim Intcircle as Integer
For intcircle = 0 to 3
Dim Dtrow as DataRow

            dtrow = Dtnew.newrow
             dtrow (0) = Watts + intcircle
             Dtrow (1) = 3500 + * Intcircle
             dtNew.Rows.Add (dtrow)
        Next
         Dim Dtview as New DataView
        Dtview = Dtnew.defaultview
        dtview.allownew = false                ' Eliminate new lines
         Dtview.allowdelete = false         ' does not allow users to delete rows via the DELETE key on the keyboard
         Me.DataGrid1.DataSource = Dtview

End Sub

Press F5 to try, the result came out!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.