mercredi 28 décembre 2016

Limiting Checked in the datagridview and get data from it to label

Please help me. I have some problem on my code. I have a Datagridview with Checkbox column in it. My system is a library system. i want the user to borrow only 2 books. and my problem is. 1. I want to limit the user to checked only to 2. 2. And i want to get some data for example the book title and the author to a label.

Please help me.

Public Sub BorrowBook()

    Dim Message As String = String.Empty
Dim Message1 As String = String.Empty
Dim Message2 As String = String.Empty
Dim Message3 As String = String.Empty
Dim Message4 As String = String.Empty
    Dim Message5 As String = String.Empty

    For Each row As DataGridViewRow In Form5.DataGridView1.Rows
        Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("checkBoxColumn").Value)
        isSelected += 1
        If isSelected = 1 Then
            Message = row.Cells("BookID").Value.ToString()
            Message1 = row.Cells("CallNumber").Value.ToString()
            Message2 = row.Cells("Title").Value.ToString()

        ElseIf isSelected = 2 Then
            Message3 = row.Cells("BookID").Value.ToString()
            Message4 = row.Cells("CallNumber").Value.ToString()
            Message5 = row.Cells("Title").Value.ToString()

        End If
    Next
    Form5.Label17.Text = Message
    Form5.Label25.Text = Message1
    Form5.Label21.Text = Message2
    Form5.Label20.Text = Message3
    Form5.Label26.Text = Message4
    Form5.Label19.Text = Message5
End Sub




Aucun commentaire:

Enregistrer un commentaire