473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

System.Windows.Forms.DataGrid.AddNewRow()

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 17 '05 #1
3 1285
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 17 '05 #2
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 17 '05 #3
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 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: max | last post by:
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...
3
by: max | last post by:
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...
3
by: max | last post by:
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...
0
by: Mike | last post by:
Hi, I have a collection object bound to a data grid, after I remove an item from the collection, the minute I click on the datagrid I get an error saying the specified argument was out of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.