2011-12-08 46 views
0

下面的代碼工作列表視圖,但我想,而不是使用列表視圖如何改變列表框,而不是列表視圖

LST =從下面的代碼

Dim idx as integer 
    idx = 1 
     lst.ListItems.Clear 
     If Emp.Employees.RecordCount > 0 Then 
      Emp.Employees.MoveFirst 
      While Not Employees.EOF 
       lst.ListItems.Add idx, , EmployeeID 
       lst.ListItems(idx).ListSubItems.Add , , FirstName 
       If IsAssigned(EmployeeID, CurrentSchedule) Then 
        lst.ListItems(idx).Checked = True 
       Else 
        lst.ListItems(idx).Checked = False 
       End If 
       idx = idx + 1 
       Employees.MoveNext 
      Wend 
     End If 

列表框的名字是列表視圖列表框lstbox

我試圖

lstbox.selected(I) = true不能代替工作的lst.ListItems(idx).Checked = True

回答

2
with aListbox 
    .Clear 
    '//loop here 
     .additem "The Item Text" 
     '//add the numeric id value 
     .itemdata(.NewIndex) = 112233 
     '//check it 
     if (condition) then 
      .Selected(.NewIndex) = True 
     end if 
end with 

'//sample click 
msgbox aListbox.list(aListbox.listindex) & " id=" & aListbox.itemdata(aListbox.listindex) 
+1

你還需要到'.Style'屬性設置爲'vbListBoxCheckbox'展現檢查。 – Deanna