Hi,
i have problem when addnew row at keyup event for datagridview control.
i want to add one row when method addRow() called.
this my code :
vb.net Code:
Public Class Form2 Dim dt As New DataTable("view") Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load dt.Columns.Add(New DataColumn("Col1")) dt.Columns.Add(New DataColumn("Col2")) dg.DataMember = "view" dg.DataSource = dt End Sub 'new rows Private Sub btnAddRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddRow.Click addRow() End Sub Sub addRow() Dim dr As DataRow dr = dt.NewRow dr.Item(0) = "" dr.Item(1) = "" dt.Rows.Add(dr) End Sub Private Sub dg_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dg.KeyUp If e.KeyData = Keys.Enter Then Dim cCol = dg.CurrentCell.ColumnIndex If cCol = 1 Then addRow() End If 'End Select End If End Sub End Class
the problem at dg_KeyUp code, Since more than 1 row created while I want only 1 line only.
thank you




Reply With Quote