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!