您好我正在寻找2天我没有找到任何工作 我有booklist datagridview,它在数据库中绑定,并且有一个未绑定的复选框列和另一个用于在表单中存储检查行的dgv。
因此,当我在booklist中检查了一行时,它将存储在另一个dgv中,所以当我对其进行排序时,检查状态将不会被删除
Private Sub BooksDataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles BooksDataGridView.CellFormatting
For Each row As DataGridViewRow In BooksDataGridView.Rows
If row.Cells("Edit").Value = False Then
row.Cells(0).Style.BackColor = Color.FromArgb(0, 41, 75)
Else
row.Cells(0).Style.BackColor = Color.SeaGreen
row.Cells(0).Style.SelectionBackColor = Color.MediumSeaGreen
End If
Next
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim tid = DataGridView1.Rows(i).Cells(0).Value
Dim sid = DataGridView1.Rows(i).Cells(1).Value
Dim type = DataGridView1.Rows(i).Cells(2).Value
For j As Integer = 0 To BooksDataGridView.RowCount - 1
If BooksDataGridView.Rows(j).Cells(1).Value = tid And BooksDataGridView.Rows(j).Cells(2).Value = sid And type = "Book" Then
BooksDataGridView.Rows(j).Cells("Edit").Value = True
BooksDataGridView.Rows(j).Cells("stat").Value = 1
End If
Next
Next
'BooksDataGridView.Sort(BooksDataGridView.Columns(20), System.ComponentModel.ListSortDirection.Descending)
End Sub
单元格格式化通过在另一个dgv
中循环来保持检查状态现在我的问题是我要将已检查的行整理到图书清单的顶部
离。
| Book Title Author |
|☐ Harry Potter 1 J.k Rowling|
|☑ Harry Potter 2 J.k Rowling|
|☐ Harry Potter 3 J.k Rowling|
|☑ Harry Potter 4 J.k Rowling|
|☐ Harry Potter 5 J.k Rowling|
|☑ Harry Potter 6 J.k Rowling|
|☑ Harry Potter 7 J.k Rowling|
To
| Book Title Author |
|☑ Harry Potter 2 J.k Rowling|
|☑ Harry Potter 4 J.k Rowling|
|☑ Harry Potter 6 J.k Rowling|
|☑ Harry Potter 7 J.k Rowling|
|☐ Harry Potter 1 J.k Rowling|
|☐ Harry Potter 3 J.k Rowling|
|☐ Harry Potter 5 J.k Rowling|