With A Data Grid View and Row enter

Gary Simpson 471 Reputation points
2023-03-31T09:59:31.4566667+00:00

Hi Good People

I have a Data Grid View, And when the Form Loads The Data Grid View is Populated with all the records I have in my database.

I have created a search which shows only the data I am Looking for. I also have Labels corresponding to the Data.

Now my Issue is, When I click A row in the Data Grid View. I want to put the value of each Data Grid View Columns into the corresponding Labels.

Does Any of you good people know if this can be achieved. I have tried different way to no avail

Kind Regards

Gary


 Private Sub DGVPaymentReceived_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DGVPaymentReceived.RowEnter


    End Sub
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,569 questions
0 comments No comments
{count} votes

Accepted answer
  1. LesHay 7,126 Reputation points
    2023-03-31T11:10:24.1133333+00:00

    Hi

    If you really want to use the RowEnter event, then a completely different approach is needed.

    Here is a stand alone example that may be of use to you. The area that you ask about is where I have the Label1.DayaBindings ....... (4 labels shown). If you want to try this example out then: A new Project, add a DataGridView named 'DGV', a ComboBox named 'CB', Label1, Label2, Label3 and Label4. Copy/Replace the Form1 code with this code.

    NOTE: the ComboBox is just there to show you the advantage of using the data in this way.

    111

    ' Form1 with DataGridView named 'DGV',
    ' ComboBox named 'CB', Label1, Label2,
    ' Label3 and Label4
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim dt As New DataTable
      Dim BS As New BindingSource
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With dt
          .Columns.Add("code", GetType(String))
          .Columns.Add("First Name", GetType(String))
          .Columns.Add("Last Name", GetType(String))
          .Columns.Add("Account#", GetType(String))
    
          ' some dummyn data
          .Rows.Add("AZ23BY675", "Les", "Hay", "WX33861A")
          .Rows.Add("PQ7ZXT368", "Hossam", "Smith", "KK449834Z")
          .Rows.Add("WWP988GTW", "Some", "body", "HP451187D")
          .Rows.Add("SK59UGG", "Else", "Here", "FR9885465W")
        End With
        BS.DataSource = dt
        DGV.DataSource = BS
    
        With CB
          .DataSource = BS
          .DisplayMember = "Code"
          .ValueMember = "Account#"
          .DropDownStyle = ComboBoxStyle.DropDown
          .AutoCompleteMode = AutoCompleteMode.SuggestAppend
          .AutoCompleteSource = AutoCompleteSource.ListItems
        End With
    
        Label1.DataBindings.Add("Text", BS, "Code")
        Label2.DataBindings.Add("Text", BS, "First Name")
        Label3.DataBindings.Add("Text", BS, "Last Name")
        Label4.DataBindings.Add("Text", BS, "Account#")
      End Sub
    End Class
    
    

0 additional answers

Sort by: Most helpful