Re: System.Windows.Forms.DataGrid.AddNewRow() by max
max
Mon Sep 26 21:57:31 CDT 2005
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]"
<vb2ae@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:017ej1tuj5u7g4chqgnsit3c7mfko8jimd@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
>