#1, I would think that too, but as I noted both rowenter and rowleave
give the same results.
#2, How do I bind the textbox to the value in column 17 of the currently
selected row in the datagridview?
My code:
Public Class Form1
Dim mydt As New DataTable
Dim MySqlConnection As New SqlClient.SqlConnection
Dim MySqlCommand As New SqlClient.SqlCommand
Dim MySqlAdapter As New SqlClient.SqlDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MySqlConnection.ConnectionString = "........."
MySqlCommand.CommandText = "select * from Checks"
MySqlCommand.Connection = MySqlConnection
MySqlAdapter.SelectCommand = MySqlCommand
mydt.Clear()
mydt.Columns.Clear()
DataGridView1.DataSource = Nothing
Try
MySqlAdapter.Fill(mydt)
For x As Int32 = 1 To 16
mydt.Columns(x).ReadOnly = True
Next
mydt.Columns(18).ReadOnly = True
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Exit Sub
End Try
DataGridView1.DataSource = mydt
DataGridView1.AutoResizeColumns()
End Sub
Private Sub DataGridView1_RowPostPaint(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEvent Args)
Handles DataGridView1.RowPostPaint
If Not IsDBNull(DataGridView1.CurrentRow.Cells(17).Value) Then
TextBox1.Text = DataGridView1.CurrentRow.Cells(17).Value
End If
End Sub
End Class
Jeffrey Tan[MSFT] wrote:
Hi Cj,
#1, I think DataGridView.RowEnter is more suitable for your requirement; in
this event, DataGridViewCellEventArgs.RowIndex should report the current
enterring row index. If not, can you provide a simple sample to demonstrate
your problem?
#2, Just as Jack suggested, you may also bind the TextBox to the same
datasource as the DataGridView. Winform databinding mechanisum will help to
ensure the data synchronization between these two controls.
Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.