By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

System.Windows.Forms.DataGrid.AddNewRow()

P: n/a
max
I can generate this error by NOT assigning a tableName to the view:

at System.Windows.Forms.DataGrid.AddNewRow()
at System.Windows.Forms.DataGridAddNewRow.OnEdit()

Is there any possibility of getting an event from the AddNewRow()? I
would like to make some changes to the row prior to the user typing in
the DataGrid.

Thanks,
--max
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

There is not an event but you can try something like this.

Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Dim da As SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As SqlConnection
Dim strConn As String

strConn = "Server = (local);"
strConn &= "Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * from products", conn)
da.Fill(ds, "Products")

DataGrid1.DataSource = ds.Tables("Products")

cm = CType(Me.BindingContext(DataGrid1.DataSource), CurrencyManager)
Button1.Enabled = False
End Sub

Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Button1.Enabled = True
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cmd As New SqlCommandBuilder(da)

da.Update(ds.Tables("Products"))
ds.AcceptChanges()

Button1.Enabled = False

End Sub

Private Sub cm_PositionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.PositionChanged
If cm.Position >= ds.Tables("Products").Rows.Count Then
' new row is added
Button1.Enabled = True
' you can try something like this
DataGrid1.Item(cm.Position, 1) = "Test"
End If
End Sub
End Class
Ken
-------------------
<max> wrote in message news:01********************************@4ax.com...
I can generate this error by NOT assigning a tableName to the view:

at System.Windows.Forms.DataGrid.AddNewRow()
at System.Windows.Forms.DataGridAddNewRow.OnEdit()

Is there any possibility of getting an event from the AddNewRow()? I
would like to make some changes to the row prior to the user typing in
the DataGrid.

Thanks,
--max

Nov 21 '05 #2

P: n/a
Mat
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Hi,

There is not an event but you can try something like this.

Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Dim da As SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As SqlConnection
Dim strConn As String

strConn = "Server = (local);"
strConn &= "Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * from products", conn)
da.Fill(ds, "Products")

DataGrid1.DataSource = ds.Tables("Products")

cm = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)
Button1.Enabled = False
End Sub

Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Button1.Enabled = True
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cmd As New SqlCommandBuilder(da)

da.Update(ds.Tables("Products"))
ds.AcceptChanges()

Button1.Enabled = False

End Sub

Private Sub cm_PositionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.PositionChanged
If cm.Position >= ds.Tables("Products").Rows.Count Then
' new row is added
Button1.Enabled = True
' you can try something like this
DataGrid1.Item(cm.Position, 1) = "Test"
End If
End Sub
End Class
Ken
-------------------
Visual Basic?
Mat
<max> wrote in message news:01********************************@4ax.com...
I can generate this error by NOT assigning a tableName to the view:

at System.Windows.Forms.DataGrid.AddNewRow()
at System.Windows.Forms.DataGridAddNewRow.OnEdit()

Is there any possibility of getting an event from the AddNewRow()? I
would like to make some changes to the row prior to the user typing in
the DataGrid.

Thanks,
--max


Nov 21 '05 #3

P: n/a
max
Thanks Ken, I'll give it a try. I am very interested in finding out
how I can have access to the row before the user gets to enter data.
It seems to me the process should be easier. On the web.gui you can
get a OnChangedRow event.

Thanks again,
--max

On Sun, 25 Sep 2005 22:13:50 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

There is not an event but you can try something like this.

Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Dim da As SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As SqlConnection
Dim strConn As String

strConn = "Server = (local);"
strConn &= "Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * from products", conn)
da.Fill(ds, "Products")

DataGrid1.DataSource = ds.Tables("Products")

cm = CType(Me.BindingContext(DataGrid1.DataSource), CurrencyManager)
Button1.Enabled = False
End Sub

Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Button1.Enabled = True
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cmd As New SqlCommandBuilder(da)

da.Update(ds.Tables("Products"))
ds.AcceptChanges()

Button1.Enabled = False

End Sub

Private Sub cm_PositionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.PositionChanged
If cm.Position >= ds.Tables("Products").Rows.Count Then
' new row is added
Button1.Enabled = True
' you can try something like this
DataGrid1.Item(cm.Position, 1) = "Test"
End If
End Sub
End Class
Ken
-------------------
<max> wrote in message news:01********************************@4ax.com...
I can generate this error by NOT assigning a tableName to the view:

at System.Windows.Forms.DataGrid.AddNewRow()
at System.Windows.Forms.DataGridAddNewRow.OnEdit()

Is there any possibility of getting an event from the AddNewRow()? I
would like to make some changes to the row prior to the user typing in
the DataGrid.

Thanks,
--max


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.