VB6到VBNet - ListBox.Selected

时间:2012-06-12 18:37:10

标签: vb.net vb6 listbox vb6-migration

我目前有一个select-case,它将从记录集中读取一个名称字段,并从该记录集中读取一个布尔值,该值假定是否将该字段包含在稍后将生成的报告中

问题是,在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,但当然不行。

1 个答案:

答案 0 :(得分:5)