VB.Net限制检查datagridview并从中获取数据到标签 [英] VB.Net Limiting Checked in the datagridview and get data from it to label

查看:178
本文介绍了VB.Net限制检查datagridview并从中获取数据到标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我
我的vb代码有一些问题。我有一个Datagridview与其中的复选框列。我的系统是一个图书馆系统。我想让用户只借2本书。我的问题是。
1.我想限制用户检查只有2.
2.当行被检查时,我想获取一些数据,例如书名和作者,并将其放在标签上



请帮助我。

  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。空
Dim Message4 As String = String.Empty
Dim Message5 As String = String.Empty

对于每一行作为DataGridViewRow在Form5.DataGridView1.Rows
Dim isSelected As Boolean = Convert.ToBoolean(row.Cells(checkBoxColumn)。value)
isSelected + = 1
如果isSelected = 1然后
Message = row.Cells(BookID)。 Value.ToString()
Message1 = row.Cells(CallNumber)Value.ToString()
Message2 = row.Cells(Title)。 lue.ToString()

ElseIf isSelected = 2然后
Message3 = row.Cells(BookID)。Value.ToString()
Message4 = row.Cells(CallNumber ).Value.ToString()
Message5 = row.Cells(Title)Value.ToString()

结束如果
下一个
Form5.Label17 .Text =消息
Form5.Label25.Text = Message1
Form5.Label21.Text = Message2
Form5.Label20.Text = Message3
Form5.Label26.Text = Message4
Form5.Label19.Text = Message5
End Sub


解决方案

您可以尝试使用列表(作为表单级别变量),并在检查后如果List.Contains(RowId)(其中RowId是行的唯一索引)然后从列表中删除 OrElse check 如果List.Count< 2 添加 RowId到列表。



之后,您可以检查具有ID到列表的行,并取消选中从列表中删除的那些。


Please help me. I have some problem on my vb 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 when the row was check i want to get some data for example the book title and the author and put it 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

解决方案

You can try using a List (as Form level variable) and, after checking If List.Contains(RowId) (where RowId is an unique index of the row) Then Remove it from the List OrElse check If List.Count < 2 and Add the RowId to the List.

After that you can check the rows having the Id into the List and uncheck the ones removed from the list.

这篇关于VB.Net限制检查datagridview并从中获取数据到标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆