【发布时间】:2021-03-08 13:36:10
【问题描述】:
我正在处理一个数据表,其中一列是一个复选框。
在加载要显示的数据时,我尝试了以下不同的选项,但都没有成功
Using BatchHead As DataTable = _SQL.GetDBDataTableSimple(SQLString)
If Not BatchHead Is Nothing Then
For iI = 0 To BatchHead.Rows.Count - 1
If _StopLoading Then Exit Sub
With TheGridView
.Rows.Add()
.Rows(.RowCount - 1).Cells(0).Value = BatchHead.Rows(iI).Item("THEID")
.Rows(.RowCount - 1).Cells(1).Value = BatchHead.Rows(iI).Item("BatchCode")
.Rows(.RowCount - 1).Cells(2).Value = Format(CDate(BatchHead.Rows(iI).Item("TransDate")), "dd/MM/yyyy")
If BatchHead.Rows(iI).Item("Printed") = "Y" Then .Rows(.RowCount - 1).Cells(3).Value = Format(CDate(BatchHead.Rows(iI).Item("PrintedDate")), "dd/MM/yyyy")
If BatchHead.Rows(iI).Item("Released") = "Y" Then .Rows(.RowCount - 1).Cells(4).Value = Format(CDate(BatchHead.Rows(iI).Item("ReleasedDate")), "dd/MM/yyyy")
.Rows(.RowCount - 1).Cells(5).Value = BatchHead.Rows(iI).Item("UserCreated")
.Rows(.RowCount - 1).Cells(6).Value = NullLng(BatchHead.Rows(iI).Item("TheCount"))
'-------------------------------------
I have tried the following combination
.Rows(.RowCount - 1).Cells(7).Value = TheGridView.CurrentCell.Selected
.Rows(.RowCount - 1).Cells(7).Value = True
.Rows(.RowCount - 1).Cells(7).Value = Accept.TrueValue
.Rows(.RowCount - 1).Cells(7).Value = Accept.FalseValue
'-------------------------------------
If BatchType = BatchTypes.PromotionSimple Then
If BatchHead.Rows(iI).Item("Status") = "AL" Then
.Rows(.RowCount - 1).DefaultCellStyle.BackColor = Color.Yellow
.Rows(.RowCount - 1).DefaultCellStyle.SelectionBackColor = Color.Green
'.Rows(.RowCount - 1).DefaultCellStyle.SelectionForeColor = Color.Black
.Rows(.RowCount - 1).Cells(7).Value = "AL"
.Rows(.RowCount - 1).Cells(8).Value = "NO"
ElseIf BatchHead.Rows(iI).Item("Status") = "AF" Then
.Rows(.RowCount - 1).DefaultCellStyle.BackColor = Color.Yellow
.Rows(.RowCount - 1).DefaultCellStyle.SelectionBackColor = Color.Green
'.Rows(.RowCount - 1).DefaultCellStyle.SelectionForeColor = Color.Black
.Rows(.RowCount - 1).Cells(7).Value = "AF"
.Rows(.RowCount - 1).Cells(8).Value = "YES"
ElseIf BatchHead.Rows(iI).Item("Status") = "OF" Then
.Rows(.RowCount - 1).Cells(7).Value = "OF"
.Rows(.RowCount - 1).Cells(8).Value = "YES"
ElseIf BatchHead.Rows(iI).Item("Status") = "CO" Then
.Rows(.RowCount - 1).Cells(7).Value = "OF"
.Rows(.RowCount - 1).Cells(8).Value = "YES"
Else
.Rows(.RowCount - 1).Cells(7).Value = ""
.Rows(.RowCount - 1).Cells(8).Value = "NO"
End If
If (Not CBool(setting.some_setting) Then
.Rows(.RowCount - 1).Cells(9).Value = selectedBatches.Contains(.Rows(.RowCount - 1).Cells(0).Value)
End If
ElseIf BatchType = BatchTypes.Promotion Then
If BatchHead.Rows(iI).Item("Status") = "OF" Then
.Rows(.RowCount - 1).Cells(7).Value = "OF"
.Rows(.RowCount - 1).Cells(8).Value = "YES"
Else
.Rows(.RowCount - 1).Cells(7).Value = ""
.Rows(.RowCount - 1).Cells(8).Value = "NO"
End If
If (Not CBool(setting.some_setting)) Then
.Rows(.RowCount - 1).Cells(9).Value = selectedBatches.Contains(.Rows(.RowCount - 1).Cells(0).Value)
End If
Else
If (Not CBool(setting.some_setting)) Then
.Rows(.RowCount - 1).Cells(7).Value = selectedBatches.Contains(.Rows(.RowCount - 1).Cells(0).Value)
End If
End If
Application.DoEvents()
End With
Next
End If
End Using
任何想法将不胜感激
【问题讨论】:
-
直接修改数据源。数据表中的列应该是布尔值,因此为选中设置 True,为未选中设置 False。将数据表设置为 BindingSource 的数据源,然后将 BindingSource 设置为 DataGridView 的数据源