我目前有一个选择案例,它将从记录集中读取名称字段,并从该记录集中读取布尔值,假设确定是否将该字段包含在稍后将生成的报告中。
问题是,在 VB6 中,您可以为 ListBox.Selected(i) 分配一个布尔值
现在,我一生都无法弄清楚将其分配给什么,根据记录集中的布尔值选择或不选择该字段。
代码:
Do Until rs_1.EOF
'Until we run out of records ...
str_FieldName = rs_1.Fields("FieldName").Value
b_IncludeField = rs_1.Fields("IncludeInBatchReport").Value
Select Case str_FieldName
Case "Sequence"
listbox_Fields.Items.Add("Sequence")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "BldgNo"
listbox_Fields.Items.Add("BldgNo")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "BldgName"
listbox_Fields.Items.Add("BldgName")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "BldgFunc"
listbox_Fields.Items.Add("BldgFunc")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "POC"
listbox_Fields.Items.Add("POC")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Phone"
listbox_Fields.Items.Add("Phone")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "AH_Phone"
listbox_Fields.Items.Add("AH_Phone")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Batch"
listbox_Fields.Items.Add("Batch")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Status"
listbox_Fields.Items.Add("Status")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Region_Req"
listbox_Fields.Items.Add("Region_Req")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Region_Alt"
listbox_Fields.Items.Add("Region_Alt")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Region_Fin"
listbox_Fields.Items.Add("Region_Fin")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
Case "Comments"
listbox_Fields.Items.Add("Comments")
listbox_Fields.SelectedItem(listbox_Fields.Items.Count - 1) = b_IncludeField
End Select
rs_1.MoveNext()
'... until we run out of records.
Loop
如您所见,我已经尝试过 SelectedItem,但这当然行不通。