datagrid cell
Thank!
Thank!
to get to the text boxes which are hosted in the grid you need to create a table style that maps to the list displayed in the grid. then you get to the list of data grid columns and from that you can use the dataGridTextBoxColumn::TextBox property to hook the TextChanged event handler.
Anyway, I went ahead and coded this up so you could try it. Please excuse the lack of wrapping here.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Friend WithEvents DataSet11 As WindowsApplication10.DataSet1
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents ProductStyle As System.Windows.Forms.DataGridTableStyle
Friend WithEvents ProductIDColumn As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents ProductNameColumn As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter()
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
Me.DataSet11 = New WindowsApplication10.DataSet1()
Me.DataGrid1 = New System.Windows.Forms.DataGrid()
Me.ProductStyle = New System.Windows.Forms.DataGridTableStyle()
Me.ProductIDColumn = New System.Windows.Forms.DataGridTextBoxColumn()
Me.ProductNameColumn = New System.Windows.Forms.DataGridTextBoxColumn()
Me.Label1 = New System.Windows.Forms.Label()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() _
{New System.Data.Common.DataTableMapping("Table", "Products", _
New System.Data.Common.DataColumnMapping() _
{New System.Data.Common.DataColumnMapping("ProductID", "ProductID"), _
New System.Data.Common.DataColumnMapping("ProductName", "ProductName")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT ProductID, ProductName FROM Products"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=(local);initial catalog=Northwind;integrated security=SSPI;persist se" & _
"curity info=False;user id=sa;workstation id=TPWINXP;packet size=4096"
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
Me.DataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd"
'
'DataGrid1
'
Me.DataGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DataSet11.Products
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 40)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(216, 216)
Me.DataGrid1.TabIndex = 0
Me.DataGrid1.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.ProductStyle})
'
'ProductStyle
'
Me.ProductStyle.DataGrid = Me.DataGrid1
Me.ProductStyle.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.ProductIDColumn, Me.ProductNameColumn})
Me.ProductStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.ProductStyle.MappingName = "Products"
'
'ProductIDColumn
'
Me.ProductIDColumn.Format = ""
Me.ProductIDColumn.FormatInfo = Nothing
Me.ProductIDColumn.HeaderText = "ID"
Me.ProductIDColumn.MappingName = "ProductID"
Me.ProductIDColumn.Width = 75
'
'ProductNameColumn
'
Me.ProductNameColumn.Format = ""
Me.ProductNameColumn.FormatInfo = Nothing
Me.ProductNameColumn.HeaderText = "Product Name"
Me.ProductNameColumn.MappingName = "ProductName"
Me.ProductNameColumn.Width = 75
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(176, 23)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Label1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(232, 262)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.DataGrid1})
Me.MinimumSize = New System.Drawing.Size(240, 296)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private WithEvents myTextBox As TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DataSet11)
Dim dgCol As DataGridTextBoxColumn = DirectCast(Me.ProductStyle.GridColumnStyles("ProductName"), DataGridTextBoxColumn)
myTextBox = dgCol.TextBox
Label1.DataBindings.Add("Text", myTextBox, "Text")
End Sub
End Class
Check out the column styles on the grid--the code relies on having those styles created, so you can retrieve a reference to the editing textbox.