473,326 Members | 2,196 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,326 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
Sep 25 '05 #1
3 2110
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

Sep 26 '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


Sep 26 '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


Sep 27 '05 #4

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

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
0
by: Victor Crudu | last post by:
Hi, could somebody help me to solve the follwing problem ? I get the following exception when i set as the DataSource of a DataGrid a DataTable. This situation can be only if I change...
0
by: sarah | last post by:
Using .NET C# installed Framework 1.1 with Service Pack 1 I have a MDI application in C# that contains 3 different forms. Form 1 has several controls one of which is a DataGrid control that...
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...
5
by: Sanddevil | last post by:
Hi there - I hope someone out there can help me! I'm using a .Net DataGrid Class to show the results of a SQL query in a spreadsheet type control. The code, which works fine is: iRowCount =...
3
by: mahtan | last post by:
Please help I have the problem that when I change the data in a Windows.Forms.DataGrid by a separate thread the following Exception is thrown: ThreadSystem.NullReferenceException in...
1
by: melanieab | last post by:
Hi, I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but then decided to try this instead: ...
1
by: Rajesh Kumar Choudhary | last post by:
Hi, I want to use the system.windows.form.datagrid control present in .net 2005 or 2003. Is it possible to use this? Please let me know if it is not supported. I have seen and used the classes...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.