以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 关于CheckedListBox 追加列表项问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=166146) |
-- 作者:wh420 -- 发布时间:2021/5/20 16:04:00 -- 关于CheckedListBox 追加列表项问题 想把EXCEL文件的所有SHEET名称追加到CheckedListBox例表项中,但执行下面代码会死循环 Dim lb As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") Dim file As Object = e.Form.Controls("TextBox3").value Dim App As New MSExcel.Application app.DisplayAlerts=False \'是否显示EXCEL警示 Dim Wb As MSExcel.WorkBook Dim Ws As MSExcel.WorkSheet Wb = App.WorkBooks.Open(file) For k As Integer = 1 To wb.workSheets.Count \'//多个sheet的处理 Ws = Wb.WorkSheets(k) lb.ComboList = Ws.name & vbcrlf & lb.ComboList Next app.quit()
|
-- 作者:有点蓝 -- 发布时间:2021/5/20 16:07:00 -- For k As Integer = 1 To wb.workSheets.Count \'//多个sheet的处理 Ws = Wb.WorkSheets(k) lb.ComboList = Ws.name & "|" & lb.ComboList Next app.quit()
|
-- 作者:wh420 -- 发布时间:2021/5/20 17:36:00 -- 收到谢谢。 CheckedListBox根据条件来设置每个添加项的不同颜色,如何实现? For k As Integer = 1 To wb.workSheets.Count \'//多个sheet的处理 Ws = Wb.WorkSheets(k) If Ws.Visible = -1 Then lb.ComboList = Ws.name & "|" & lb.ComboList ‘该项为红色 lb.CheckedIndices(1) = Color.red Else ’该项为黑色 lb.ComboList = Ws.name & "|" & lb.ComboList lb.ForeColor = Color.blue End If Next |
-- 作者:有点蓝 -- 发布时间:2021/5/20 20:12:00 -- 设置不了 |
-- 作者:wh420 -- 发布时间:2021/5/21 13:55:00 -- 那如果是If Ws.Visible = -1 Then “当前项设置为选中状态呢?这个能实现不? |
-- 作者:有点蓝 -- 发布时间:2021/5/21 14:09:00 -- dim str as string dim lst as new list(of integer) For k As Integer = 1 To wb.workSheets.Count \'//多个sheet的处理 Ws = Wb.WorkSheets(k) str = str & "|" & Ws.name If Ws.Visible = -1 Then lst.add(k-1) End If Next lb.ComboList = str.trim("|") for each i as integer = 0 to lst.count - 1 lb.SetItemChecked(lst(i), true) next
|
-- 作者:wh420 -- 发布时间:2021/5/21 16:55:00 -- 问题解决,谢谢老师。 |