Imports System.Data.DataTable
Public Class Form2
Dim table As New DataTable("table")
Dim index As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
table.Columns.Add("ID", Type.GetType("System.Int32"))
table.Columns.Add("First name", Type.GetType("System.String"))
table.Columns.Add("Last name", Type.GetType("System.String"))
table.Columns.Add("Sum", Type.GetType("System.Int32"))
DataGridView1.DataSource = table
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
table.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)
DataGridView1.DataSource = table
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
index = e.RowIndex
Dim selectedrow As DataGridViewRow
selectedrow = DataGridView1.Rows(index)
TextBox1.Text = selectedrow.Cells(0).Value.ToString
TextBox2.Text = selectedrow.Cells(1).Value.ToString
TextBox3.Text = selectedrow.Cells(2).Value.ToString
TextBox4.Text = selectedrow.Cells(3).Value.ToString
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim newdata As DataGridViewRow
newdata = DataGridView1.Rows(index)
newdata.Cells(0).Value = TextBox1.Text
newdata.Cells(1).Value = TextBox2.Text
newdata.Cells(2).Value = TextBox3.Text
newdata.Cells(3).Value = TextBox4.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
DataGridView1.Rows.RemoveAt(index)
End Sub
End Class
No comments:
Post a Comment