0

i've tried the other solution(like changing item that should be shown on data) but i think i've never gotten the point to resolving. Thank you in advance whoever can answer my problem...

Screenshot of the problem

Screenshot of the problem


Private Sub dgEmp_Click(sender As Object, e As EventArgs) Handles dgEmp.Click
    LoadEmployeeInfo(dgEmp.SelectedRows.Item(0).Index)

End Sub

Private Sub LoadEmployee(Optional q As String = "")
    list.Query = "Select id,lastname,firstname,middlename,sss,philh,pag,rate,cola,mStatus,free_insurance,mp,mpvalue from tblemployee where (lastname like'%" & q & "%'  or firstname like'%" & q & "%' or middlename  like'%" & q & "%') and deactive='No' order by lastname,firstname,middlename"

    list.datagrid = dgEmp
    list.LoadRecords()
    If list.RecordCount = Nothing Then Exit Sub

    LoadEmployeeInfo(dgEmp.SelectedRows.Item(0).Index)
End Sub
Public Sub LoadEmployeeInfo(index As Integer)
    With dgEmp.Rows(index)
        id = .Cells(0).Value
        lblName.Text = .Cells(1).Value & ", " & .Cells(2).Value & " " & .Cells(3).Value
        rpd = .Cells(7).Value
        lblRate.Text = Format(rpd, "#,##0.000000000")
        cola = .Cells(8).Value
        lblAllo.Text = Format(cola, "#,##0.000000000")
        otrate = (rpd / 8) * 1.25
        lblOTRate.Text = Format(otrate, "#,##0.000000000")
        IsSSS = ConvertToBoolean(.Cells(4).Value)
        IsPH = ConvertToBoolean(.Cells(5).Value) 'add
        IsPAG = ConvertToBoolean(.Cells(6).Value) 'pos
        IsMP = ConvertToBoolean(.Cells(11).Value)
        IsFI = ConvertToBoolean(.Cells(10).Value)
        CStatus = .Cells(9).Value
        MPV = .Cells(12).Value
    End With

    ThisPayroll.Query = "Select * from tblpayroll where payrollperiod=? and empid=?"
    ThisPayroll.AddParam("@payrollperiod", GetPeriod)
    ThisPayroll.AddParam("@empid", id)
    ThisPayroll.ExecQuery()

    If ThisPayroll.RecordCount = Nothing Then
        isUpdate = False
        txtReg_Days.Text = 0
        txtReg_OT.Text = 0
        txtSP_Days.Text = 0
        txtSP_OT.Text = 0
        txtHoliday.Text = 0
        txtHolidayOT.Text = 0
        txtLate.Text = 0
        txtAdjustment.Text = 0
        txtSSSL.Text = 0
        txtHDMFL.Text = 0
        txtCA.Text = 0
        txtDMA.Text = 0
        txtRice.Text = 0
        txtCloth.Text = 0
        txtEmpMed.Text = 0
        txtLaundry.Text = 0
        txtMeal.Text = 0
    Else
        With ThisPayroll.DataSource
            isUpdate = True
            txtReg_Days.Text = .Rows(0)("regday")
            txtReg_OT.Text = .Rows(0)("ot")
            txtSP_Days.Text = .Rows(0)("spday")
            txtSP_OT.Text = .Rows(0)("spdayot")
            txtHoliday.Text = .Rows(0)("lholiday")
            txtHolidayOT.Text = .Rows(0)("lhot")
            txtLate.Text = .Rows(0)("hlate")
            txtAdjustment.Text = .Rows(0)("salary_adj")
            txtSSSL.Text = .Rows(0)("sss_loan")
            txtHDMFL.Text = .Rows(0)("pag_loan")
            txtCA.Text = .Rows(0)("cash_advance")
            txtDMA.Text = .Rows(0)("depmed")
            txtRice.Text = .Rows(0)("ricesub")
            txtCloth.Text = .Rows(0)("clothing")
            txtEmpMed.Text = .Rows(0)("empmed")
            txtLaundry.Text = .Rows(0)("laundry")
            txtMeal.Text = .Rows(0)("meal")

        End With
    End If
    Compute()
End Sub
juharr
  • 31,741
  • 4
  • 58
  • 93
Monica
  • 29
  • 4

1 Answers1

0

If you cannot make sure that something is selected elsewhere, you can last-minute check it like this:

Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
    If dgEmp.SelectedRows.Count > 0 Then
        LoadEmployeeInfo(dgEmp.SelectedRows.Item(0).Index)
    End If
End Sub

It works only because you're using index zero, or else you would have to be careful for your index, too. Of course, this is assuming that dgEmp is not Nothing...

Also, notice that I attached this to the SelectionChanged event, as I don't think that the Click event will give you what you want, but I'll let that part for you to deal with. Have fun!

laancelot
  • 3,138
  • 2
  • 14
  • 21