Search code examples
vb.netdatagridviewmdimdichild

Display current row of datagridview of childform in the status bar of the parent mdi form in vb.net


Following is the requirement and for which i have coded the code. When a user enters a new row in data gridview that current row should be displayed in the parent MDI form's status bar,i have put a label there and in that label text the current row's all the cells value should be displayed.i have the below code in child form but its not working.i have also attached the image of the mdi form along with childenter image description here form

Private Sub dgsalesitem_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgsalesitem.Leave
    Dim X As DataGridViewCell
    Dim v As String
    v = ""
    For Each X In dgsalesitem.SelectedRows

        v = v + X.Value
    Next
    MDILoad.lbltoolstripstatus.Text = v

End Sub

Solution

  • Try This Code

    Private Sub DataGridView1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Leave
    
            Dim x As String = String.Empty
    
            For xi As Integer = 0 To DataGridView1.ColumnCount - 1
    
                x += Trim(DataGridView1.CurrentRow.Cells(xi).Value)
    
            Next
    
            CType(Me.MdiParent, Object).ToolStripStatusLabel1.Text = x
    
        End Sub